Skip to main content

Grove-LED Button

El Grove - LED Button está compuesto por Grove - Yellow Button, Grove - Blue LED Button y Grove - Red LED Button. Este botón es estable y confiable con una larga vida útil de 100 000 veces. Con el LED incorporado, puedes aplicarlo a muchos proyectos interesantes, es realmente útil usar el LED para mostrar el estado del botón. Utilizamos un MOSFET de canal N de alta calidad para controlar el LED para asegurar una alta velocidad de conmutación y un bajo consumo. En resumen, ¿quieres algunos botones realmente increíbles? Aquí los tienes...

Versión

Versión del ProductoCambiosFecha de Lanzamiento
Grove-LED ButtonInicialJun 2018

Versión

Versión del ProductoCambiosFecha de Lanzamiento
Grove-LED ButtonInicialJun 2018

Versión

Versión del ProductoCambiosFecha de Lanzamiento
Grove-LED ButtonInicialJun 2018

Características

  • Larga vida útil de funcionamiento
  • Fácil de usar
  • Interfaz digital Grove

Especificaciones

ElementoValor
Voltaje de trabajo3.3V/5V
Vida útil de funcionamiento sin carga100 000 veces
Corriente nominal del LED50mA
Resistencia de presión^1^<100mΩ
Resistencia de liberación^2^>100MΩ
TamañoL: 40mm A: 20mm H: 13mm
Peso4.3g
Tamaño del paqueteL: 140mm A: 90mm H: 10mm
Peso bruto11g
tip

1,2- Si desea medir la resistencia, retire la tapa de la tecla de la placa. De lo contrario, obtendrá el valor de la resistencia equivalente de la placa en lugar de la resistencia real de la tapa de la tecla.

Descripción general del hardware

Mapa de pines

Esquemático

SIG1 es la señal de control del LED, el valor predeterminado es bajo, por lo que el MOSFET de canal N está apagado, el LED también está apagado. Cuando SIG1 se vuelve alto, el MOSFET de canal N se enciende, y el LED se ilumina.

SIG2 se conecta al pin del botón. Con una resistencia pull-up, el valor predeterminado de SIG2 es alto. Cuando presiona el botón, el voltaje se reduce, el SIG2 se vuelve bajo.

Plataformas compatibles

ArduinoRaspberry Pi

Comenzando

tip

En esta parte, usamos el Grove - Red LED Button como ejemplo. Las siguientes partes también se aplican al Amarillo y Azul.

Jugar Con Arduino

Hardware

Materiales requeridos

Seeeduino V4.2Base ShieldGrove- Red LED Button
enter image description hereenter image description hereenter image description here
Get One NowGet One NowGet One Now
  • Paso 1. Grove- Red LED Button al puerto D3 del Grove-Base Shield.

  • Paso 2. Conecta Grove - Base Shield al Seeeduino.

  • Paso 3. Conecta Seeeduino a la PC mediante un cable USB.

note

Si no tenemos Grove Base Shield, también podemos conectar directamente este módulo al Seeeduino como se muestra a continuación.

SeeeduinoGrove- Red LED Button
5VRojo
GNDNegro
SIG2Blanco
SIG1Amarillo

Software

note

Si esta es la primera vez que trabajas con Arduino, te recomendamos encarecidamente que veas Primeros pasos con Arduino antes de comenzar.

  • Paso 1. Abre el IDE de Arduino y crea un nuevo archivo, luego copia el siguiente código en el nuevo archivo.
#include "Arduino.h"

//1: toggle mode, 2: follow mode
#define LED_MODE 1

const int ledPin = 3; // the number of the LED pin, D3
const int buttonPin = 4; // the number of the pushbutton pin, D4
const boolean breathMode = true; // if or not the led lights as breath mode when it's on

// Variables will change:
int ledState = LOW; // the current state of the output pin
int ledFadeValue = 0;
int ledFadeStep = 5;
int ledFadeInterval = 20; //milliseconds
int buttonState; // the current reading from the input pin
int lastButtonState = HIGH; // the previous reading from the input pin

unsigned long lastDebounceTime = 0; // the last time the output pin was toggled
unsigned long debounceDelay = 50; // the debounce time; increase if the output flickers
unsigned long lastLedFadeTime = 0;

void setup() {
pinMode(buttonPin, INPUT);
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, ledState);
}

void loop() {
int reading = digitalRead(buttonPin);

// If the switch changed, due to noise or pressing:
if (reading != lastButtonState) {
// reset the debouncing timer
lastDebounceTime = millis();
}

if ((millis() - lastDebounceTime) > debounceDelay) {
// whatever the reading is at, it's been there for longer
// than the debounce delay, so take it as the actual current state:

// if the button state has changed:
if (reading != buttonState) {
buttonState = reading;

#if LED_MODE == 1
if (buttonState == LOW) { //button is pressed
ledState = !ledState;
ledFadeValue = 0;
lastLedFadeTime = millis();
}
#else
if (buttonState == LOW) { //button is pressed
ledState = HIGH;
ledFadeValue = 0;
lastLedFadeTime = millis();
} else { //button is released
ledState = LOW;
}
#endif
}
}

// set the LED:
if (breathMode && ledState != LOW) {
if (millis() - lastLedFadeTime > ledFadeInterval) {
lastLedFadeTime = millis();
analogWrite(ledPin, ledFadeValue);
ledFadeValue += ledFadeStep;
if (ledFadeValue > 255){
ledFadeValue = 255 - ledFadeStep;
ledFadeStep = -ledFadeStep;
} else if (ledFadeValue < 0) {
ledFadeValue = 0;
ledFadeStep = -ledFadeStep;
}
}
} else {
digitalWrite(ledPin, ledState);
}

lastButtonState = reading;
}

tip

En esta demostración, elegimos el modo 1 que es el modo de alternancia, puedes cambiar la línea 4 #define LED_MODE 1 por #define LED_MODE 2 para usar el modo de seguimiento.

  • Paso 2. Sube la demostración. Si no sabes cómo subir el código, por favor revisa Cómo subir código.

  • Paso 3. Ahora, intenta presionar tu botón, verás que el LED se enciende con un efecto de aparición/desaparición gradual.

Debería verse así:

Jugar Con Raspberry Pi

Hardware

  • Paso 1. Elementos utilizados en este proyecto:
Raspberry piGrove Base Hat para RasPiGrove - Botón LED Rojo
enter image description hereenter image description hereenter image description here
Consigue UNO AhoraConsigue UNO AhoraConsigue UNO Ahora
  • Paso 2. Conecta el Grove Base Hat al Raspberry.
  • Paso 3. Conecta el botón LED rojo al puerto D5 del Base Hat.
  • Paso 4. Conecta el Raspberry Pi a la PC a través del cable USB.

note

Para el paso 3 puedes conectar el botón LED a cualquier Puerto GPIO pero asegúrate de cambiar el comando con el número de puerto correspondiente.

Software

caution

Si estás usando Raspberry Pi con Raspberrypi OS >= Bullseye, tienes que usar esta línea de comandos solo con Python3.

  • Paso 1. Sigue Configuración de Software para configurar el entorno de desarrollo.
  • Paso 2. Descarga el archivo fuente clonando la biblioteca grove.py.
sudo pip3 install Seeed-grove.py
cd ~
git clone https://github.com/Seeed-Studio/grove.py

  • Step 3. Excute below commands to run the code.
cd grove.py/grove
sudo python3 grove_ryb_led_button.py 5

A continuación se muestra el código grove_ryb_led_button.py.


import time
from grove.button import Button
from grove.factory import Factory

class GroveLedButton(object):
def __init__(self, pin):
# High = light on
self.__led = Factory.getOneLed("GPIO-HIGH", pin)
# Low = pressed
self.__btn = Factory.getButton("GPIO-LOW", pin + 1)
self.__on_event = None
self.__btn.on_event(self, GroveLedButton.__handle_event)

@property
def on_event(self):
return self.__on_event

@on_event.setter
def on_event(self, callback):
if not callable(callback):
return
self.__on_event = callback

def __handle_event(self, evt):
# print("event index:{} event:{} pressed:{}".format(evt['index'], evt['code'], evt['presesed']))
if callable(self.__on_event):
self.__on_event(evt['index'], evt['code'], evt['time'])
return

self.__led.brightness = self.__led.MAX_BRIGHT
event = evt['code']
if event & Button.EV_SINGLE_CLICK:
self.__led.light(True)
print("turn on LED")
elif event & Button.EV_DOUBLE_CLICK:
self.__led.blink()
print("blink LED")
elif event & Button.EV_LONG_PRESS:
self.__led.light(False)
print("turn off LED")


Grove = GroveLedButton

def main():
from grove.helper import SlotHelper
sh = SlotHelper(SlotHelper.GPIO)
pin = sh.argv2pin()

ledbtn = GroveLedButton(pin)

# remove ''' pairs below to begin your experiment
'''
# define a customized event handle your self
def cust_on_event(index, event, tm):
print("event with code {}, time {}".format(event, tm))

ledbtn.on_event = cust_on_event
'''
while True:
time.sleep(1)


if __name__ == '__main__':
main()


tip

Si todo va bien, podrás ver que el LED se enciende si lo presionas y se apaga si lo mantienes presionado. Si haces doble clic en el botón del LED, el LED parpadeará.


pi@raspberrypi:~/grove.py/grove $ python3 grove_ryb_led_button.py 5
Hat Name = 'Grove Base Hat RPi'
turn on LED
turn on LED
blink LED
turn on LED
turn off LED
^CTraceback (most recent call last):
File "grove_ryb_led_button.py", line 101, in <module>
main()
File "grove_ryb_led_button.py", line 97, in main
time.sleep(1)
KeyboardInterrupt

Puedes salir de este programa simplemente presionando ++ctrl+c++.

Visor Esquemático Online

Recursos

Soporte Técnico y Discusión de Productos


¡Gracias por elegir nuestros productos! Estamos aquí para brindarle diferentes tipos de soporte para asegurar que su experiencia con nuestros productos sea lo más fluida posible. Ofrecemos varios canales de comunicación para satisfacer diferentes preferencias y necesidades.

Loading Comments...