Advertisement
hidromotic

Untitled

Apr 21st, 2020
620
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.84 KB | None | 0 0
  1. #define PIN_BOTON  8
  2. #define CONFIGURAR_BOTON pinMode(PIN_BOTON, INPUT)
  3. #define BOTON_PRESIONADO (digitalRead(PIN_BOTON)==HIGH)
  4.  
  5. #define PIN_LED 13
  6. #define CONFIGURAR_LED pinMode(PIN_LED, OUTPUT)
  7. #define ENCENDER_LED digitalWrite(PIN_LED, HIGH)
  8. #define APAGAR_LED digitalWrite(PIN_LED, LOW)
  9.  
  10. void setup()
  11.   {
  12.   CONFIGURAR_BOTON;
  13.   CONFIGURAR_LED;
  14.   ENCENDER_LED;
  15.   }
  16.  
  17. bool SePresionoBoton(void)
  18.   {
  19.   static bool boton_presionado_ant=false;
  20.  
  21.   if(BOTON_PRESIONADO == boton_presionado_ant) return(false);
  22.   boton_presionado_ant=BOTON_PRESIONADO;
  23.  
  24.   return(BOTON_PRESIONADO);
  25.   }
  26.  
  27. void loop()
  28.   {
  29.     unsigned long tiempo = 0;
  30. if (SePresionoBoton()){
  31.    if (millis - tiempo > 50){
  32.       tiempo = millis();
  33.    }
  34. }
  35. if(SePresionoBoton())  //Si se presionĂ³ el boton
  36.     ENCENDER_LED;
  37.     delay(5000); //esperamos 5 segundo
  38.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement