Advertisement
Guest User

Xmas Tree lights project for MakeUseOf.com

a guest
Dec 3rd, 2011
2,884
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.17 KB | None | 0 0
  1. int leds[] = {2,3,4,5,6,7,8,9,10}; // 9 total
  2.  
  3. void setup(){
  4.    for(int i = 0;i<90;i++){
  5.        pinMode(leds[i],OUTPUT);
  6.    }
  7. }
  8.  
  9. void loop(){
  10.    oneAtATime();
  11.    //randomSequence();
  12.    //topToBottom();
  13. }
  14. // Turns each LED off one at a time
  15. void oneAtATime(){
  16.   for(int i = 0;i< 9;i++){
  17.       digitalWrite(leds[i],HIGH);
  18.       delay(100);
  19.       digitalWrite(leds[i],LOW);
  20.    }
  21. }
  22.  
  23. // utterly random , a a kind of twinkling effect is acheived?
  24. void randomSequence(){
  25.    
  26.   int randomLed = random(0,9);
  27.   digitalWrite(leds[randomLed],HIGH);
  28.       delay(50);
  29.  
  30.   randomLed = random(0,9);
  31.   digitalWrite(leds[randomLed],LOW);
  32.  
  33. }
  34.  
  35. // HOMEWORK: This one goes from top to bottom
  36. void topToBottom(){
  37.   int d = 100;
  38.  
  39.   for(int i = 0;i< 5;i++){
  40.      digitalWrite(leds[4-i],HIGH);
  41.      digitalWrite(leds[4+i],HIGH);
  42.      delay(d);
  43.      digitalWrite(leds[4+i],LOW);
  44.      digitalWrite(leds[4-i],LOW);
  45.      delay(d);
  46.  
  47.    }
  48.    
  49.    for(int i = 4;i> 0;i--){
  50.      digitalWrite(leds[4-i],HIGH);
  51.      digitalWrite(leds[4+i],HIGH);
  52.      delay(d);
  53.      digitalWrite(leds[4+i],LOW);
  54.      digitalWrite(leds[4-i],LOW);
  55.      delay(d);
  56.  
  57.    }
  58.  
  59. }
  60.  
  61.  
  62.  
  63.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement