Advertisement
hidromotic

Untitled

Apr 8th, 2025
429
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.15 KB | Software | 0 0
  1. #define PIN_LED 13
  2. #define CONFIG_LED    pinMode(PIN_LED, OUTPUT)
  3. #define ENCENDER_LED  digitalWrite(PIN_LED, HIGH)
  4. #define APAGAR_LED    digitalWrite(PIN_LED, LOW)
  5. #define MS_ESPERA_LED 250
  6. //#define MS_APAGADO    100
  7. //#define MS_ENCENDIDO  3000
  8.  
  9. #define PIN_BOTON 8
  10. #define CONFIG_BOTON      pinMode(PIN_BOTON, INPUT)
  11. #define BOTON_PRESIONADO  (digitalRead(PIN_BOTON)==HIGH)
  12.  
  13. bool blink_habilitado=1;
  14.  
  15. void setup() {
  16.   CONFIG_LED;
  17.   CONFIG_BOTON;
  18.   }
  19.  
  20. void loop()
  21.   {
  22.   if(blink_habilitado) Blink();
  23.  
  24.   CtrlBoton();
  25.   }
  26.  
  27. void CtrlBoton(void)
  28.   {
  29.   static bool boton_presionado_ant=0;
  30.  
  31.   if(BOTON_PRESIONADO==boton_presionado_ant) return;  //Detecta el evento
  32.   boton_presionado_ant=BOTON_PRESIONADO;
  33.  
  34.   if(!BOTON_PRESIONADO) return;
  35.  
  36.   //ACCION
  37.   blink_habilitado=!blink_habilitado;
  38.   }
  39.  
  40. void Blink(void)
  41.   {
  42.   static unsigned long millis_ini=0;
  43.   static bool estado_led=0; //Se podría declarar bool
  44.  
  45.   //ESPERA POR EL EVENTO
  46.   if( (millis() - millis_ini) < MS_ESPERA_LED ) return; //Sale
  47.   millis_ini=millis();
  48.  
  49.   //ACCIÓN
  50.   estado_led = !estado_led;
  51.   if(estado_led) ENCENDER_LED;
  52.   else           APAGAR_LED;
  53.   }
  54.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement