SHARE
TWEET

Arduino Christmas Lights

a guest Dec 19th, 2017 620 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const int led_count = 12; // Number of leds
  2. const int led_delay = 150; // A delay constant
  3. const int led_pins[led_count] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13}; // Pins of the leds
  4.  
  5. void off() {        // All leds off
  6.   for (int i = 0; i <= led_count; i++) {
  7.     digitalWrite(led_pins[i], LOW);
  8.   }
  9.   delay(led_delay * 5);
  10. }
  11.  
  12. void basic() {      // Basic animation
  13.   for (int j = 0; j <= led_count; j++) {
  14.     digitalWrite(led_pins[j], HIGH);
  15.     delay(led_delay);
  16.   }
  17.   off();
  18. }
  19.  
  20. void chaser() {     // Chaser animation
  21.   for (int j = 0; j <= led_count; j++) {
  22.     digitalWrite(led_pins[j], HIGH);
  23.     delay(led_delay);
  24.     digitalWrite(led_pins[j-1], LOW);
  25.     delay(led_delay);
  26.   }
  27.   off();
  28. }
  29.  
  30. void pairs() {      // Pairs animation
  31.   for (int j = 0; j <= led_count; j++) {
  32.     digitalWrite(led_pins[j], HIGH);
  33.     digitalWrite(led_pins[j + 2], HIGH);
  34.     delay(led_delay * 1.5);
  35.     digitalWrite(led_pins[j], LOW);
  36.     digitalWrite(led_pins[j + 2], LOW);
  37.   }
  38.   off();
  39. }
  40.  
  41. void randoms() {    // Random leds animation   
  42.   for (int o = 0; o <= 50; o++) {
  43.     int r = random(1,12);
  44.     digitalWrite(led_pins[r], HIGH);
  45.     delay(led_delay);
  46.     digitalWrite(led_pins[r], LOW);
  47.   }
  48.   off();
  49. }
  50.  
  51. void setup() {
  52.   for (int i = 0; i <= led_count - 1; i++) {        // Initializing the pins
  53.     pinMode(led_pins[i], OUTPUT);
  54.   }
  55.   off();
  56. }
  57.  
  58. void loop() {  
  59.   basic();
  60.   chaser();
  61.   pairs();
  62.   randoms();
  63.   delay(1000);
  64. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top