Guest User

meteorShower

a guest
Jan 14th, 2014
521
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.43 KB | None | 0 0
  1. /*
  2. meteorShower is an adaptation, by Jon Burroughs, of some funkboxing code from Thomas Eldridge
  3. FastLED 2.0 ready
  4. */
  5. //================================================
  6. #include "FastLED.h"
  7. #define LED_COUNT 80
  8. #define LED_PIN 4
  9. struct CRGB leds[LED_COUNT];
  10. //================================================
  11.  
  12. byte ledsX[LED_COUNT][3];
  13. boolean RAINBOWs = false;
  14. boolean RANDOMpick = false;
  15. uint8_t hue;
  16. uint16_t timeframe;
  17. byte idex = 0;
  18. byte colorTIP = 0;
  19. byte meteorLENGTH;
  20. byte loopCount = 1; //low number loop counter
  21.  
  22. void setup() {
  23. // sanity check delay - allows reprogramming if accidently blowing power w/leds
  24. delay(2000);
  25. // LEDS.addLeds<WS2811, 13>(leds, NUM_LEDS);
  26. // LEDS.addLeds<TM1809, 13>(leds, NUM_LEDS);
  27. // LEDS.addLeds<TM1803, 13>(leds, NUM_LEDS);
  28. // LEDS.addLeds<P9813>(leds, NUM_LEDS);
  29. // CLEDController *pLed = new ClocklessController_Trinket<4, NS(400), NS(400), NS(450), GRB>();
  30. // LEDS.addLeds(pLed, leds, NUM_LEDS);
  31. // LEDS.addLeds<LPD8806>(leds, NUM_LEDS);
  32. // LEDS.addLeds<WS2801>(leds, NUM_LEDS);
  33. // LEDS.addLeds<SM16716>(leds, NUM_LEDS);
  34. // LEDS.addLeds<WS2811, 11>(leds, NUM_LEDS);
  35. // Put ws2801 strip on the hardware SPI pins with a BGR ordering of rgb and limited to a 1Mhz data rate
  36. // LEDS.addLeds<WS2801, 11, 13, BGR, DATA_RATE_MHZ(1)>(leds, NUM_LEDS);
  37. // LEDS.addLeds<LPD8806, 10, 11>(leds, NUM_LEDS);
  38. // LEDS.addLeds<WS2811, 13, BRG>(leds, NUM_LEDS);
  39. // LEDS.addLeds<LPD8806, BGR>(leds, NUM_LEDS);
  40. LEDS.setBrightness(198);
  41. FastLED.addLeds<UCS1903, LED_PIN, RBG>(leds, LED_COUNT);
  42. }
  43.  
  44. void loop(){
  45. meteorShower();
  46. }
  47.  
  48. void meteorShower(){
  49. //hue master
  50. hue++;
  51.  
  52. //populate the leds[] with stored ledsX[] array data
  53. for(byte i = 0; i < LED_COUNT; i++ ) {
  54. ledsX[i][0] = leds[i].r;
  55. ledsX[i][1] = leds[i].g;
  56. ledsX[i][2] = leds[i].b;
  57. }
  58. //clear the previous counter clockwise position
  59. byte iCCW;
  60.  
  61. //we are keeping track of elapsed time
  62. timeframe++; //fx timer
  63.  
  64. //meteorLENGTH fx is only shown for this time frame
  65. if((timeframe >= 1) && (timeframe <= 280)) { meteorLENGTH = 29; }
  66. if((timeframe > 280) && (timeframe <= 500)) { meteorLENGTH = 45; }
  67.  
  68. //RAINBOWs fx add rainbow tails during this time frame only
  69. if((timeframe > 0) && (timeframe <= 280)) { RAINBOWs = true; }
  70. else{ RAINBOWs = false; }
  71. //keep our RAINBOWs within a specific range of hue
  72. if(RAINBOWs == true){ hue = hue - 20; if(hue <= 0){ hue = 1; } }
  73.  
  74. //RANDOMpick fx is only enabled during this timeframe
  75. if((timeframe > 600) && (timeframe <= 790)) { RANDOMpick = true; }
  76. else{ RANDOMpick = false; }
  77.  
  78. //pick a random spot in the meteor switch case statement below
  79. if (RANDOMpick == true){ idex = random8(46); }
  80. else{
  81. //increment the meteor display frame
  82. idex++;
  83. //make sure we don't drift into space
  84. if (idex > meteorLENGTH) { idex = 0; } }
  85.  
  86. //meteorLENGTH is randomized during this timeframe only
  87. if((timeframe > 790) && (timeframe <= 1090)) { meteorLENGTH = random8(7, 38); }
  88.  
  89. //during this point in the animation timeframe
  90. if(timeframe == 1180) {
  91. //reset the timeframe
  92. timeframe = 0;
  93. //increment the loop counter
  94. loopCount++;
  95. }
  96.  
  97. //during this part of the loopCount, all meteors have a white colored tip
  98. if(loopCount == 1) { colorTIP = 0; }
  99. if(loopCount == 2) { colorTIP = 1; }
  100. if(loopCount == 3) { colorTIP = random8(11); }
  101. //end of the desired fx, reset the variable for the next time around
  102. if(loopCount == 4) {
  103. colorTIP = 0;
  104. loopCount = 0;
  105. }
  106.  
  107. //there are two switch case statements nestled into one another
  108. //we always want to control the color of the meteor tip
  109. //the other controls the actual meteor animation in 45 frames/case statements
  110. switch (idex) {
  111. case 0:
  112. switch (colorTIP){
  113. case 0:
  114. leds[0] = CHSV(hue, 255, 255);
  115. break;
  116. case 1:
  117. leds[0] = CRGB(100,100,100);
  118. break;
  119. case 2:
  120. leds[0] = CRGB::Yellow;
  121. break;
  122. case 3:
  123. leds[0] = CRGB::Violet;
  124. break;
  125. case 4:
  126. leds[0] = CRGB::Green;
  127. break;
  128. case 5:
  129. leds[0] = CRGB::Purple;
  130. break;
  131. case 6:
  132. leds[0] = CRGB::Orange;
  133. break;
  134. case 7:
  135. leds[0] = CRGB::Cyan;
  136. break;
  137. case 8:
  138. leds[0] = CRGB::GreenYellow;
  139. break;
  140. case 9:
  141. leds[0] = CRGB::Magenta;
  142. break;
  143. case 10:
  144. leds[0] = CRGB::SkyBlue;
  145. }
  146. break;
  147. case 1:
  148. leds[0] = CHSV((hue - 20), 255, 210);
  149. break;
  150. case 2:
  151. leds[0] = CHSV((hue - 22), 255, 180);
  152. break;
  153. case 3:
  154. leds[0] = CHSV((hue - 23), 255, 150);
  155. break;
  156. case 4:
  157. leds[0] = CHSV((hue - 24), 255, 110);
  158. break;
  159. case 5:
  160. leds[0] = CHSV((hue - 25), 255, 90);
  161. break;
  162. case 6:
  163. leds[0] = CHSV((hue - 26), 160, 60);
  164. break;
  165. case 7:
  166. leds[0] = CHSV((hue - 27), 140, 40);
  167. break;
  168. case 8:
  169. leds[0] = CHSV((hue - 28), 120, 20);
  170. break;
  171. case 9:
  172. leds[0] = CHSV((hue - 29), 100, 20);
  173. break;
  174. case 10:
  175. leds[0] = CRGB::Black;
  176. break;
  177. case 11:
  178. leds[0] = CRGB::Black;
  179. break;
  180. case 12:
  181. leds[0] = CRGB::Black;
  182. break;
  183. case 13:
  184. leds[0] = CRGB::Black;
  185. break;
  186. case 14:
  187. leds[0] = CRGB::Black;
  188. break;
  189. case 15:
  190. leds[0] = CRGB::Black;
  191. break;
  192. case 16:
  193. leds[0] = CRGB::Black;
  194. break;
  195. case 17:
  196. leds[0] = CRGB::Black;
  197. break;
  198. case 18:
  199. leds[0] = CRGB::Black;
  200. break;
  201. case 19:
  202. leds[0] = CRGB::Black;
  203. break;
  204. case 20:
  205. leds[0] = CRGB::Black;
  206. break;
  207. case 21:
  208. leds[0] = CRGB::Black;
  209. break;
  210. case 22:
  211. leds[0] = CRGB::Black;
  212. break;
  213. case 23:
  214. leds[0] = CRGB::Black;
  215. break;
  216. case 24:
  217. leds[0] = CRGB::Black;
  218. break;
  219. case 25:
  220. leds[0] = CRGB::Black;
  221. break;
  222. case 26:
  223. leds[0] = CRGB::Black;
  224. break;
  225. case 27:
  226. leds[0] = CRGB::Black;
  227. break;
  228. case 28:
  229. leds[0] = CRGB::Black;
  230. break;
  231. case 29:
  232. leds[0] = CRGB::Black;
  233. break;
  234. case 30:
  235. leds[0] = CRGB::Black;
  236. break;
  237. case 31:
  238. leds[0] = CRGB::Black;
  239. break;
  240. case 32:
  241. leds[0] = CRGB::Black;
  242. break;
  243. case 33:
  244. leds[0] = CRGB::Black;
  245. break;
  246. case 34:
  247. leds[0] = CRGB::Black;
  248. break;
  249. case 35:
  250. leds[0] = CRGB::Black;
  251. break;
  252. case 36:
  253. leds[0] = CRGB::Black;
  254. break;
  255. case 37:
  256. leds[0] = CRGB::Black;
  257. break;
  258. case 38:
  259. leds[0] = CRGB::Black;
  260. break;
  261. case 39:
  262. leds[0] = CRGB::Black;
  263. break;
  264. case 40:
  265. leds[0] = CRGB::Black;
  266. break;
  267. case 41:
  268. leds[0] = CRGB::Black;
  269. break;
  270. case 42:
  271. leds[0] = CRGB::Black;
  272. break;
  273. case 43:
  274. leds[0] = CRGB::Black;
  275. break;
  276. case 44:
  277. leds[0] = CRGB::Black;
  278. break;
  279. case 45:
  280. leds[0] = CRGB::Black;
  281. break;
  282. }
  283. //copy the LED Array
  284. for(byte i = 1; i < LED_COUNT; i++ ) {
  285. iCCW = adjacent_ccw(i);
  286. leds[i].r = ledsX[iCCW][0];
  287. leds[i].g = ledsX[iCCW][1];
  288. leds[i].b = ledsX[iCCW][2];
  289. }
  290. //show the blinky
  291. FastLED.show();
  292. //control the animation speed/frame rate
  293. delay(30);
  294. }
  295.  
  296. //find the adjacent counter clockwise postion of the led
  297. //funkboxing code snippet
  298. byte adjacent_ccw(byte i) {
  299. byte r;
  300. if (i > 0) { r = i - 1; }
  301. else { r = LED_COUNT - 1; }
  302. return r;
  303. }
Advertisement
Add Comment
Please, Sign In to add comment