Advertisement
hidromotic

Barra de Leds en Arduino

Apr 10th, 2024
789
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.80 KB | Software | 0 0
  1. #define PIN_LED1 0
  2. #define PIN_LED2 1
  3. #define PIN_LED3 2
  4. #define PIN_LED4 3
  5. #define PIN_LED5 4
  6. #define PIN_LED6 5
  7. #define CANT_LEDS 6
  8.  
  9. const int pin_led[]={PIN_LED1, PIN_LED2, PIN_LED3, PIN_LED4, PIN_LED5, PIN_LED6};
  10.  
  11. #define CONFIG_LED(x) pinMode(pin_led[x], OUTPUT)
  12. #define LED_ON(x)     digitalWrite(pin_led[x], HIGH)
  13. #define LED_OFF(x)    digitalWrite(pin_led[x], LOW)
  14. #define MS_ESPERA 100
  15.  
  16. void setup() {
  17.   for(int i=0; i<CANT_LEDS; i++)  CONFIG_LED(i);
  18.   }
  19.  
  20. void loop() {
  21.   Barra();
  22.   }
  23.  
  24. void Barra(void)
  25.   {
  26.   static unsigned long millis_ant=0;
  27.   static int i=0;
  28.  
  29.   //Evento sincrónico
  30.   if(millis() - millis_ant < MS_ESPERA) return;
  31.   millis_ant=millis();
  32.  
  33.   if(i>= (2*CANT_LEDS)) i=0;
  34.   if(i<CANT_LEDS)   LED_ON(i);
  35.   else              LED_OFF(2*CANT_LEDS-i-1);
  36.  
  37.   i++;
  38.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement