Guest User

America Sequence

a guest
Feb 4th, 2014
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.13 KB | None | 0 0
  1. #include "FastSPI_LED2.h"
  2. #define NUM_LEDS 50 // Number of LED's
  3.  
  4. CRGB leds[NUM_LEDS]; // This is an array of leds. One item for each led in your strip.
  5.  
  6. // Not necessary to define SPI data, clock, etc pins because that is done in the FastSPI library
  7. // FastSPI recognizes arduino type
  8.  
  9. int a=9,b=0,c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0;
  10.  
  11. void setup() {
  12.  
  13. delay(2000); // sanity check delay - allows reprogramming if accidently blowing power w/leds
  14.  
  15. FastLED.addLeds<SM16716, RGB>(leds, NUM_LEDS); //chipset type
  16. }
  17.  
  18. void loop() {
  19. //************************** AMERICA *********************************
  20. int NUM_LOOPS = 20;
  21. int LOOP_NUM = 0;
  22. while(a < 50){
  23. if(a < 9){ //for leds to come out 1 by one, can't assign leds[negative#] = ....
  24. for(int BEGIN = 0; BEGIN < 9; BEGIN ++){
  25. if(BEGIN >= 0) leds[BEGIN] = CRGB::Red; //if assign - number to led, program fails
  26. if(BEGIN > 0) leds[BEGIN - 1] = CRGB::Red;
  27. if(BEGIN > 1) leds[BEGIN - 2] = CRGB::White;
  28. if(BEGIN > 2) leds[BEGIN - 3] = CRGB::White;
  29. if(BEGIN > 3) leds[BEGIN - 4] = CRGB::White;
  30. if(BEGIN > 4) leds[BEGIN - 5] = CRGB::Blue;
  31. if(BEGIN > 5) leds[BEGIN - 6] = CRGB::Blue;
  32. if(BEGIN > 6) leds[BEGIN - 7] = CRGB::Blue;
  33. if(BEGIN > 7) leds[BEGIN - 8] = CRGB::Black;
  34. FastLED.show();
  35. delay(40);
  36. }
  37. }
  38.  
  39. if(a >= 9){ //code to assign first led in the sequnce #8-49
  40. b = a-1;
  41. c = a-2;
  42. d = a-3;
  43. e = a-4;
  44. f = a-5;
  45. g = a-6;
  46. h = a-7;
  47. i = a-8;
  48. j = a-9;
  49. AMERICA(); // go to america function, assigns a-j leds their colors
  50. }
  51.  
  52. if (a == 49){ //if first LED in chain has reached last LED
  53. LOOP_NUM++; // increment loop number
  54. if(LOOP_NUM == NUM_LOOPS-1){ //if the LED chain is on its last loop
  55. for(int END = 41; END < 50; END ++){
  56. if(END < 42) leds[END + 8] = CRGB::Red; //if assign -# to led, program fails
  57. if(END < 43) leds[END + 7] = CRGB::Red;
  58. if(END < 44) leds[END + 6] = CRGB::White;
  59. if(END < 45) leds[END + 5] = CRGB::White;
  60. if(END < 46) leds[END + 4] = CRGB::White;
  61. if(END < 47) leds[END + 3] = CRGB::Blue;
  62. if(END < 48) leds[END + 2] = CRGB::Blue;
  63. if(END < 49) leds[END + 1] = CRGB::Blue;
  64. if(END < 50) leds[END] = CRGB::Black;
  65. FastLED.show();
  66. delay(40);
  67. }
  68. break; //exit the while loop right here
  69. }
  70. for(int select = 0; select < 9; select++){ //allows for fluid LED49 TO LED 0 transition
  71. switch(select){
  72.  
  73. case 0:
  74. a=0;b=49;c=48;d=47;e=46;f=45;g=44;h=43;i=42;j=41;
  75. AMERICA(); break;
  76.  
  77. case 1:
  78. a=1;b=0;c=49;d=48;e=47;f=46;g=45;h=44;i=43;j=42;
  79. AMERICA(); break;
  80.  
  81. case 2:
  82. a=2;b=1;c=0;d=49;e=48;f=47;g=46;h=45;i=44;j=43;
  83. AMERICA(); break;
  84.  
  85. case 3:
  86. a=3;b=2;c=1;d=0;e=49;f=48;g=47;h=46;i=45;j=44;
  87. AMERICA(); break;
  88.  
  89. case 4:
  90. a=4;b=3;c=2;d=1;e=0;f=49;g=48;h=47;i=46;j=45;
  91. AMERICA(); break;
  92.  
  93. case 5:
  94. a=5;b=4;c=3;d=2;e=1;f=0;g=49;h=48;i=47;j=46;
  95. AMERICA(); break;
  96.  
  97. case 6:
  98. a=6;b=5;c=4;d=3;e=2;f=1;g=0;h=49;i=48;j=47;
  99. AMERICA(); break;
  100.  
  101. case 7:
  102. a=7;b=6;c=5;d=4;e=3;f=2;g=1;h=0;i=49;j=48;
  103. AMERICA(); break;
  104.  
  105. case 8:
  106. a=8;b=7;c=6;d=5;e=4;f=3;g=2;h=1;i=0;j=49;
  107. AMERICA(); break;
  108. }
  109. }
  110. }
  111. a++; //increment a. if coming out of switch case, a now is 9.
  112.  
  113. } //end of "a" while loop
  114.  
  115.  
  116. }
  117.  
  118.  
  119. void AMERICA(){
  120. leds[a] = CRGB::Red;
  121. leds[b] = CRGB::Red;
  122. leds[c] = CRGB::Red;
  123. leds[d] = CRGB::White;
  124. leds[e] = CRGB::White;
  125. leds[f] = CRGB::White;
  126. leds[g] = CRGB::Blue;
  127. leds[h] = CRGB::Blue;
  128. leds[i] = CRGB::Blue;
  129. leds[j] = CRGB::Black;
  130. FastLED.show();
  131. delay(40); //2 seconds for leds to loop
  132. }
Advertisement
Add Comment
Please, Sign In to add comment