hidromotic

BlinkMultidestello

May 12th, 2020
807
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.15 KB | None | 0 0
  1. //Ejemplo del Blink Multidestello
  2. //12/05/20
  3. ////https://pastebin.com/EUeWirzt
  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_LED;
  13.   APAGAR_LED;
  14.   }
  15.  
  16. void BlinkMultidestello(void)
  17.   {
  18.   const unsigned char c_pulsos=3;
  19.   const unsigned int t_pulso=200;
  20.   const unsigned int t_pausa=1000;
  21.  
  22.   static bool led_encendido=0;
  23.   static unsigned long millis_ant=0;
  24.   static unsigned long tpo_espera=0;
  25.   static unsigned char pulsos_restantes=0;
  26.  
  27.   if(millis() - millis_ant < tpo_espera) return;
  28.   millis_ant=millis();
  29.  
  30.  
  31.   if(led_encendido)
  32.     {
  33.     pulsos_restantes--;
  34.     if(pulsos_restantes)  tpo_espera=t_pulso;
  35.     else                  tpo_espera=t_pausa;
  36.     }
  37.   else
  38.     {
  39.     if(!pulsos_restantes)
  40.       {
  41.       pulsos_restantes= c_pulsos;
  42.       }    
  43.     tpo_espera=t_pulso;
  44.     }
  45.    
  46.   led_encendido = !led_encendido;
  47.  
  48.   if(led_encendido) ENCENDER_LED;
  49.   else              APAGAR_LED;
  50.  
  51.   }
  52.  
  53. void loop()
  54.   {
  55.   BlinkMultidestello();
  56.   }
Add Comment
Please, Sign In to add comment