Hola a todos ,
Quiero encender dos leds con el mismo pulsador , cada uno con diferente duración de pulsación.(Espero que se pueda hacer)
Encender/Apagar el Led 1 con una pulsacion de menos de 0.200seg y el siguiente también Encendido/apagado , con una pulsación de mas de 0.5seg
La parte de encender el segundo si funciona cuando intento hacer algo con el primero , no funciona.
// Parametros
int HOLD_DELAY = 500; // Seleccionar el tiempo necesario para el segundo pulsador
int HOLD_DELAY1 = 200; // Seleccionar el tiempo necesario para el primer pulsador
int ledPin = 10 ;
int ledPin1 = 11; // LED esta conectado
int switchPin = 8; // Pulsador conectado al Pin X
// Variables
unsigned long start_hold;
boolean allow = false;
int sw_state;
int sw_laststate = LOW;
int led_state = LOW;
int led_state1 = LOW;
// Setup
void setup() {
Serial.begin(9600);
pinMode(ledPin, OUTPUT); // Configura el Pin como salida
pinMode(ledPin1, OUTPUT); // Configura el Pin como salida
pinMode(switchPin, INPUT); // Configura el Pin como entrada
}
// Loop
void loop(){
sw_state = digitalRead(switchPin); // Lectura valor entrada
if (sw_state == HIGH && sw_laststate == LOW){ // for button pressing
start_hold = millis(); // marca el tiempo
allow = true; // permite el cambio de estado del Led
}
if (allow == true && sw_state == HIGH && sw_laststate == HIGH){ // si el boton permanece presionado
if ((millis() - start_hold) >= HOLD_DELAY){ // Durante mas de x/1000 sec(s)
led_state = !led_state; // cambia estado del Led
allow = false; // prevent multiple state changes
}
//EL OTRO LED //**************************************//
if (sw_state == HIGH && sw_laststate == LOW){ // for button pressing
start_hold = millis(); // mark the time
allow = true; // allow LED state changes
}
if (allow == true && sw_state == HIGH && sw_laststate == HIGH){ // if button remains pressed
if ((millis() - start_hold) >= HOLD_DELAY1){ // for longer than x/1000 sec(s)
led_state1 = !led_state; // change state of LED
allow = false; // prevent multiple state changes
}
}
sw_laststate = sw_state;
digitalWrite(ledPin, led_state);
digitalWrite(ledPin1, led_state1);
}
}