Advertisement
hidromotic

BlinkIncremental

May 14th, 2020
1,602
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.07 KB | None | 0 0
  1. //Blink Incremental
  2. /*Iniciar con un led destellando en modo (a), luego de 10seg cambiar el destello a modo (b),
  3. y 5 segundos más tarde cambiar el destello al modo (c), luego de 5 segundos,
  4. repetir el ciclo, es decir retornar el destello al modo (a).
  5. Modos:
  6. a) t_on=200ms, período= 3seg (t_off=2800ms apagado)
  7. b) t_on=250ms, periodo= 1seg (t_off=750ms apagado)
  8. c) t_on=500ms, periodo= 1seg (t_off=500ms apagado)*/
  9.  
  10. #define PIN_LED           13
  11. #define CONFIGURAR_LED    pinMode(PIN_LED, OUTPUT)
  12. #define ENCENDER_LED      digitalWrite(PIN_LED, HIGH)
  13. #define APAGAR_LED        digitalWrite(PIN_LED, LOW)  
  14.  
  15. int modo = 0;              
  16.  
  17. void setup()
  18.   {  
  19.   CONFIGURAR_LED;
  20.   ENCENDER_LED;
  21.   Serial.begin(9600);
  22.   Serial.println("Iniciado...");
  23.   }
  24.  
  25. void loop()
  26.   {
  27.   Modo();
  28.   Led();
  29.   delay(10);            
  30.   }
  31.  
  32.  
  33.  
  34. void Modo (void)
  35.   {
  36.   const unsigned int modoA = 10000 , modoB = 5000 , modoC = 5000;
  37.   static unsigned long millis_modo=0;
  38.   static unsigned long tpo_modo= modoA;  
  39.        
  40.   if(millis()- millis_modo < tpo_modo) return;
  41.   millis_modo = millis();
  42.  
  43.   modo++;
  44.  
  45.   switch(modo)
  46.     {
  47.     case 1: tpo_modo = modoB; break;
  48.     case 2: tpo_modo = modoC; break;
  49.     default:
  50.       modo=0;
  51.       tpo_modo = modoA; break;
  52.     }
  53.    
  54.   Serial.print("modo: ");
  55.   Serial.println(modo);
  56.   }
  57.  
  58.        
  59. void Led(void)
  60.   {
  61.     const unsigned int t_offA = 2800 , t_onA = 200 , t_offB = 750 , t_onB= 250 , t_offC = 500 , t_onC = 500;
  62.     static bool estado=1;
  63.     static unsigned long millis_ant = 0;  
  64.     static unsigned long tpo_espera = t_onA;
  65.    
  66.     if(millis() - millis_ant < tpo_espera) return;
  67.     millis_ant =  millis();
  68.    
  69.     estado = !estado;
  70.        
  71.     switch (modo)
  72.       {
  73.       case 0: tpo_espera = estado ? t_onA : t_offA; break;
  74.       case 1: tpo_espera = estado ? t_onB : t_offB; break;                
  75.       case 2: tpo_espera = estado ? t_onC : t_offC; break;            
  76.       }
  77.      
  78.   if(estado)  ENCENDER_LED;
  79.   else        APAGAR_LED;
  80.    
  81.   }
  82.  
  83.   //Sketch=2658       --> 2642
  84.   //Var. Globales=226 --> 226
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement