Advertisement
Guest User

Untitled

a guest
Mar 19th, 2015
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 50.59 KB | None | 0 0
  1. #include <avr/io.h>
  2. #include <avr/wdt.h>
  3. #include <Wire.h>
  4. #include <RH_ASK.h>
  5. #include <SPI.h>
  6. #include "printf.h"
  7. #include <FastLED.h>
  8.  
  9.  
  10. RH_ASK driver(2400, 50, 49, 49, false);
  11. #define NUM_LEDS 120
  12.  
  13. CRGB leds[NUM_LEDS];
  14. // Starting height, in meters, of the ball (strip length)
  15. #define NUM_BALLS 3 // Number of bouncing balls you want (recommend < 7, but 20 is fun in its own way)
  16. float h[NUM_BALLS] ;// An array of heights
  17. float vImpact0; // Impact velocity of the ball when it hits the ground if "dropped" from the top of the strip
  18. float vImpact[NUM_BALLS] ; // As time goes on the impact velocity will change, so make an array to store those values
  19. float tCycle[NUM_BALLS] ; // The time since the last time the ball struck the ground
  20. int pos[NUM_BALLS] ;
  21. int mirror[NUM_BALLS];// The integer position of the dot on the strip (LED index)
  22. long tLast[NUM_BALLS] ; // The clock time of the last ground strike
  23. float COR[NUM_BALLS] ; // Coefficient of Restitution (bounce damping)
  24.  
  25. byte A = rand();
  26. byte B = rand();
  27. byte C = rand();
  28. byte D = rand();
  29.  
  30. byte zZone = 0;
  31. unsigned int zSpeedA;
  32. byte zonePatternA;
  33. //LED Information
  34. struct fade {
  35. unsigned char r, g, b, f;
  36. };
  37.  
  38. struct fade *lights;
  39.  
  40. //zone pattern arras
  41. byte zonePattern[46];
  42. //xxxxxxxxxxxxxxxxxx
  43. //Chasing Programs
  44. //xxxxxxxxxxxxxxxxxx
  45.  
  46. //Rainbow
  47.  
  48. byte rainbowpattern[46] = {
  49. 0, 0, 0, 0, 0, 32, 32, 32, 32, 32, 64, 64, 64, 64, 64, 96, 96, 96, 96, 96, 128, 128, 128, 128, 128, 160, 160, 160, 160, 160, 160, 192, 192, 192, 192, 192, 224, 224, 224, 224, 224, 255, 255, 255, 255, 255};
  50.  
  51. byte rainbowfadepattern[46] = {
  52. 0, 0, 8, 16, 24, 32, 32, 32, 40, 48, 56, 64, 64, 72, 78, 86, 96, 96, 96, 104, 112, 120, 128, 128, 128, 136, 144, 152, 160, 160, 160, 168, 176, 184, 192, 192, 200, 208, 216, 224, 224, 232, 240, 248, 255, 255};
  53.  
  54. byte lazer[46] = {
  55. 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 100, 255, 100, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10};
  56.  
  57. byte longstreakspattern[46] = {
  58. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 7, 7, 7, 30, 30, 30, 30, 60, 60, 60, 60, 120, 120, 120, 120, 180, 180, 180, 180, 255, 255, 255, 255};
  59.  
  60. byte shortstreakspattern[46] = {
  61. 3, 7, 60, 120, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
  62.  
  63. byte diamondfadepattern[46] = {
  64. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 3, 7, 15, 30, 45, 60, 80, 120, 140, 180, 255, 255, 180, 120, 80, 60, 45, 30, 15, 7, 3, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
  65.  
  66. byte copspattern[46] = {
  67. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 160, 160, 160, 160, 160, 160, 160, 160, 160, 160, 160, 160, 160, 160, 160, 160, 160, 160, 160, 160, 160, 160, 160};
  68.  
  69. byte twocolorchasepattern[46] = {
  70. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 2, 2, 2, 2, 2, 0, 0, 0, 0};
  71.  
  72. byte colorchasepattern[46] = {
  73. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3};
  74.  
  75.  
  76. /* faders
  77.  
  78. int fader[] = {
  79. 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2};
  80.  
  81. int faderoff[] = {
  82. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
  83.  
  84. const char faderLength = 31;
  85.  
  86. //xxxxxxxxxxxxxxxxxx
  87. //Patriotic Programs
  88. //xxxxxxxxxxxxxxxxxx
  89.  
  90. //Patriotic One
  91.  
  92. int patriotic1Red[] = {
  93. 255, 255, 255, 255, 255, 255, 0, 0, 0};
  94. int patriotic1Blue[] = {
  95. 244, 244, 244, 0, 0, 0, 255, 255, 255};
  96. int patriotic1Green[] = {
  97. 255, 255, 255, 0, 0, 0, 0, 0, 0};
  98. const char patriotic1Length = 9;
  99. */
  100.  
  101. void patternShift(int colorr[], int colorb[], int colorg[], int arraySize);
  102.  
  103.  
  104. boolean zFlag;
  105.  
  106.  
  107. typedef void (*LEDfunctions) ();
  108.  
  109. LEDfunctions functionsArray [43] =
  110. {
  111. spacing,
  112. off,
  113. custom,
  114. white,
  115. green,
  116. red,
  117. blue,
  118. yellow,
  119. orange,
  120. pink,
  121. purple,
  122. marine,
  123. grassgreen,
  124. rainbow,
  125. rainbowfade,
  126. longstreaks,
  127. shortstreaks,
  128. diamondfade,
  129. customlazer,
  130. cops,
  131. cops1,
  132. twocolorchase,
  133. bouncing,
  134. strobingC,
  135. strobingW,
  136. rainbowFade,
  137. redblueFade,
  138. redgreenFade,
  139. purpleorangeFade,
  140. aquaFade,
  141. skyFade,
  142. everyFade,
  143. veryslowFade,
  144. twinkle,
  145. randomWalk,
  146. colorrandomWalk,
  147. colorChase,
  148. colorWhipe,
  149. rainDrop,
  150. colorslide,
  151. patrioticTwinkle,
  152. christmasTwinkle,
  153. patriotic1,
  154. };
  155.  
  156. byte programInformation[8];
  157.  
  158. byte program = 0;
  159. byte hue = 1;
  160. byte saturation = 2;
  161. byte value = 3;
  162. byte special = 4;
  163. byte speed = 5;
  164. byte zone = 6;
  165. byte reply = 7;
  166.  
  167. unsigned long zstart = millis();
  168. unsigned long flasherstart = millis();
  169. unsigned long flasherstart1 = millis();
  170. byte flasherinterval = 135;
  171. byte oldProgram;
  172.  
  173.  
  174. unsigned int colorSF;
  175. byte programA = 0;
  176. boolean once;
  177.  
  178.  
  179. CHSV colorHSV;
  180.  
  181. unsigned long zSpeed;
  182. byte DisplaySpeed;
  183.  
  184.  
  185. bool onceA;
  186.  
  187. void loop()
  188. {
  189. Receive();
  190. if (onceA == 1) {
  191. onceA = 0;
  192. speak();
  193. }
  194. functionsArray [programA] ();
  195. once = 0;
  196. zoneIncrementers();
  197. FastLED.show();
  198. }
  199.  
  200. void Receive() {
  201. uint8_t buf[RH_ASK_MAX_MESSAGE_LEN];
  202. uint8_t buflen = sizeof(buf);
  203. if (driver.recv(buf, &buflen)) // Non-blocking
  204. {
  205. digitalWrite(13, HIGH);
  206. int i;
  207. // Message with a good checksum received, dump it.
  208. Serial.println("");
  209. driver.printBuffer("Got:", buf, buflen);
  210. memcpy(programInformation, buf, 8);
  211. onceA = 1;
  212. digitalWrite(13, LOW);
  213. }
  214.  
  215. }
  216.  
  217. void speedConversion() {
  218. if (DisplaySpeed == 0) {
  219. zSpeed = 5000;
  220. }
  221. else if(DisplaySpeed == 1){
  222. zSpeed = 1000;
  223. }
  224. else if(DisplaySpeed == 2){
  225. zSpeed = 925;
  226. }
  227. else if(DisplaySpeed == 3){
  228. zSpeed = 775;
  229. }
  230. else if(DisplaySpeed == 4){
  231. zSpeed = 625;
  232. }
  233. else if(DisplaySpeed == 5){
  234. zSpeed = 400;
  235. }
  236. else if(DisplaySpeed == 6){
  237. zSpeed = 275;
  238. }
  239. else if(DisplaySpeed == 7){
  240. zSpeed = 150;
  241. }
  242. else if(DisplaySpeed == 8){
  243. zSpeed = 70;
  244. }
  245. else if(DisplaySpeed == 9){
  246. zSpeed = 35;
  247. }
  248. else if(DisplaySpeed == 10){
  249. zSpeed = 15;
  250. }
  251.  
  252. }
  253.  
  254. void speak() {
  255. Serial.println("begin");
  256. Serial.println(programInformation[zone]);
  257. Serial.println(programInformation[program]);
  258. Serial.println(programInformation[hue]);
  259. Serial.println(programInformation[saturation]);
  260. Serial.println(programInformation[value]);
  261. Serial.println(programInformation[speed]);
  262. Serial.println(programInformation[special]);
  263. Serial.println("end");
  264. if(programInformation[zone] == 0){
  265. // reset();
  266. }
  267. if(programInformation[zone] == 1){
  268. programA = programInformation[program];
  269. colorHSV.h = programInformation[hue];
  270. colorHSV.s = programInformation[saturation];
  271. colorHSV.v = programInformation[value];
  272. DisplaySpeed = programInformation[speed];
  273. colorSF = programInformation[special];
  274. speedConversion();
  275. once = 1;
  276. Serial.print("Values Successfull Assigned");
  277. }
  278. }
  279.  
  280. int reset(void)
  281. {
  282. wdt_enable(WDTO_8S);
  283. while(1) {};
  284. }
  285.  
  286. void setup() {
  287. pinMode(13, OUTPUT);
  288.  
  289. FastLED.addLeds<LPD8806, 45, 43, BRG>(leds, NUM_LEDS);
  290. Serial.begin(57600);
  291. Serial.println("");
  292.  
  293. if (!driver.init()) {
  294. Serial.println("init failed");
  295. }
  296.  
  297.  
  298. Serial.println("Mode: Receiver 1");
  299. Serial.println("ready to go");
  300.  
  301. if (NUM_LEDS < 50) {
  302. vImpact0 = 3.75;
  303. }
  304. else if (NUM_LEDS < 150) {
  305. vImpact0 = 4.25;
  306. }
  307. else {
  308. vImpact0 = 5.25;
  309. }
  310. for (int i = 0 ; i < NUM_BALLS ; i++) { // Initialize variables
  311. tLast[i] = millis();
  312. h[i] = 3;
  313. pos[i] = 0; // Balls start on the ground
  314. vImpact[i] = vImpact0; // And "pop" up at vImpact0
  315. tCycle[i] = 0;
  316. COR[i] = 0.90 - float(i) / pow(NUM_BALLS, 2);
  317. }
  318.  
  319. randomSeed(analogRead(A1));
  320. // BBOUNCING BOUCING BOUCNING
  321. }
  322. void spacing() { //does nothing, so that the first array value for the color programs doesn't equal zero
  323. }
  324.  
  325. void patternShift(byte zone[]) {
  326. byte tempZone;
  327. for (byte i=0; i<45; i++)
  328. {
  329. tempZone = zone[45];
  330. zone[45] = zone[i];
  331. zone[i] = tempZone;
  332. }
  333. }
  334.  
  335. void zoneIncrementers() {
  336. unsigned long z = millis();
  337.  
  338. if(z - zstart >= zSpeed && zSpeed != 5000){
  339. patternShift(zonePattern);
  340. zFlag = !zFlag;
  341. zstart = z;
  342. }
  343. }
  344.  
  345. void FunctionForEachPixel (byte icNumber, byte index)
  346. {
  347. zZone = 0;
  348. zonePatternA = zonePattern[index];
  349. }
  350. void off() {
  351. for (byte i = 0; i < NUM_LEDS; i++) {
  352. leds[i].setRGB( 0, 0, 0);
  353. }
  354. }
  355.  
  356. void custom() {
  357. for (int i = 0; i < NUM_LEDS; i++) {
  358. leds[i] = colorHSV;
  359. }
  360. }
  361.  
  362. void white() {
  363. for (int i = 0; i < NUM_LEDS; i++) {
  364. leds[i].setHSV( 255, 0, 255);
  365. }
  366. }
  367.  
  368. void green() {
  369. for (int i = 0; i < NUM_LEDS; i++) {
  370. leds[i].setRGB( 0, 255, 0);
  371.  
  372. }
  373. }
  374.  
  375.  
  376. void red() {
  377. for (int i = 0; i < NUM_LEDS; i++) {
  378. leds[i].setRGB( 255, 0, 0);
  379. }
  380. }
  381.  
  382.  
  383. void blue() {
  384. for (int i = 0; i < NUM_LEDS; i++) {
  385. leds[i].setRGB( 0, 0, 255);
  386. }
  387. }
  388.  
  389. void yellow() {
  390. for (int i = 0; i < NUM_LEDS; i++) {
  391. leds[i].setHSV(64, 255, 255);
  392. }
  393. }
  394.  
  395. void orange() {
  396. for (int i = 0; i < NUM_LEDS; i++) {
  397. leds[i].setRGB( 255, 40, 0);
  398.  
  399. }
  400. }
  401.  
  402. void pink() {
  403. for (int i = 0; i < NUM_LEDS; i++) {
  404. leds[i].setRGB( 255, 0, 40);
  405.  
  406. }
  407. }
  408. void purple() {
  409. for (int i = 0; i < NUM_LEDS; i++) {
  410. leds[i].setRGB( 85, 0, 85);
  411. }
  412.  
  413. }
  414. void marine() {
  415. for (int i = 0; i < NUM_LEDS; i++) {
  416. leds[i].setRGB( 0, 255, 200);
  417. }
  418.  
  419. }
  420. void grassgreen() {
  421. for (int i = 0; i < NUM_LEDS; i++) {
  422. leds[i].setRGB( 60, 255, 0);
  423. }
  424.  
  425. }
  426.  
  427. void rainbow() {
  428. if (once) {
  429. Serial.println("yes");
  430. memcpy(zonePattern, rainbowpattern, 46);
  431. }
  432. for (int i = 0 ; i < NUM_LEDS; i++) {
  433. const unsigned int idx = ( i % 46);
  434. FunctionForEachPixel (i, idx);
  435. leds[i] = CHSV(zonePatternA, 255, 255);
  436. }
  437.  
  438. }
  439.  
  440. void rainbowfade() {
  441. if (once) {
  442. Serial.println("one mo gin");
  443. memcpy(zonePattern, rainbowfadepattern, 46);
  444. }
  445. for (int i = 0; i < NUM_LEDS; i++) {
  446. const unsigned int idx = ( i % 46);
  447. FunctionForEachPixel (i, idx);
  448. leds[i] = CHSV(zonePatternA, 255, 255);
  449.  
  450. }
  451. }
  452.  
  453. void longstreaks() {
  454. if (once) {
  455. memcpy(zonePattern, longstreakspattern, 46);
  456. }
  457. for (int i = 0; i < NUM_LEDS; i++) {
  458. const unsigned int idx = ( i % 46);
  459. FunctionForEachPixel (i, idx);
  460. leds[i] = colorHSV;
  461. leds[i].nscale8_video(zonePatternA);
  462. }
  463. }
  464.  
  465. void shortstreaks() {
  466. if (once) {
  467. memcpy(zonePattern, shortstreakspattern, 46);
  468. }
  469. for (int i = 0; i < NUM_LEDS; i++) {
  470. const unsigned int idx = ( i % 46);
  471. FunctionForEachPixel (i, idx);
  472. leds[i] = colorHSV;
  473. leds[i].nscale8_video(zonePatternA);
  474. }
  475.  
  476. }
  477.  
  478. void diamondfade() {
  479. if (once) {
  480. memcpy(zonePattern, diamondfadepattern, 46);
  481. }
  482. for (int i = 0; i < NUM_LEDS; i++) {
  483. const unsigned int idx = ( i % 46);
  484. FunctionForEachPixel (i, idx);
  485. leds[i] = colorHSV;
  486. leds[i].nscale8_video(zonePatternA);
  487. }
  488.  
  489. }
  490.  
  491.  
  492. void customlazer() {
  493. if (once) {
  494. memcpy(zonePattern, lazer, 46);
  495. }
  496. for (int i = 0; i < NUM_LEDS; i++) {
  497. const unsigned int idx = ( i % 46);
  498. FunctionForEachPixel (i, idx);
  499. leds[i] = colorHSV;
  500. leds[i].nscale8_video(zonePatternA);
  501. }
  502.  
  503. }
  504.  
  505. void cops() {
  506. if (once) {
  507. memcpy(zonePattern, copspattern, 46);
  508. }
  509. unsigned long flasherTime = millis();
  510. static boolean flashflag = 0;
  511. int color = 0;
  512. int color2 = 0;
  513.  
  514.  
  515. byte blinkA = (NUM_LEDS / 4) - 2;
  516. byte blinkB = (NUM_LEDS / 2) + blinkA;
  517.  
  518.  
  519. for (int i = 0; i < NUM_LEDS; i++) {
  520. const unsigned int idx = ( i % 46);
  521. FunctionForEachPixel (i, idx);
  522. leds[i] = CHSV(zonePatternA, 255, 255);
  523.  
  524.  
  525. if (flasherTime - flasherstart >= flasherinterval) {
  526. flashflag = ! flashflag;
  527. flasherstart = flasherTime;
  528. }
  529.  
  530. if (flashflag == 0) {
  531. color = 255;
  532. color2 = 0;
  533. }
  534. else {
  535. color = 0;
  536. color2 = 255;
  537. }
  538.  
  539.  
  540. if (i <= NUM_LEDS) {
  541. if (color == 255) {
  542. leds[blinkA].setRGB(color, color, color);
  543. leds[blinkA + 1].setRGB(color, color, color);
  544. leds[blinkA + 2].setRGB(color, color, color);
  545. leds[blinkA + 3].setRGB(color, color, color);
  546. if (NUM_LEDS > 60) {
  547. leds[blinkA - 1].setRGB(color, color, color);
  548. leds[blinkA - 2].setRGB(color, color, color);
  549. leds[blinkA - 3].setRGB(color, color, color);
  550. leds[blinkA - 4].setRGB(color, color, color);
  551. }
  552. if (NUM_LEDS > 100) {
  553. leds[blinkA - 5].setRGB(color, color, color);
  554. leds[blinkA - 6].setRGB(color, color, color);
  555. leds[blinkA + 4].setRGB(color, color, color);
  556. leds[blinkA + 5].setRGB(color, color, color);
  557. }
  558. if (NUM_LEDS > 150) {
  559. leds[blinkA - 7].setRGB(color, color, color);
  560. leds[blinkA - 8].setRGB(color, color, color);
  561. leds[blinkA + 6].setRGB(color, color, color);
  562. leds[blinkA + 7].setRGB(color, color, color);
  563. }
  564. if (NUM_LEDS > 200) {
  565. leds[blinkA - 9].setRGB(color, color, color);
  566. leds[blinkA - 10].setRGB(color, color, color);
  567. leds[blinkA + 8].setRGB(color, color, color);
  568. leds[blinkA + 9].setRGB(color, color, color);
  569. }
  570. }
  571. if (color2 == 255) {
  572. leds[blinkB].setRGB(color2, color2, color2);
  573. leds[blinkB + 1].setRGB(color2, color2, color2);
  574. leds[blinkB + 2].setRGB(color2, color2, color2);
  575. leds[blinkB + 3].setRGB(color2, color2, color2);
  576. if (NUM_LEDS > 60) {
  577. leds[blinkB - 1].setRGB(color2, color2, color2);
  578. leds[blinkB - 2].setRGB(color2, color2, color2);
  579. leds[blinkB - 3].setRGB(color2, color2, color2);
  580. leds[blinkB - 4].setRGB(color2, color2, color2);
  581. }
  582. if (NUM_LEDS > 100) {
  583. leds[blinkB - 5].setRGB(color2, color2, color2);
  584. leds[blinkB - 6].setRGB(color2, color2, color2);
  585. leds[blinkB + 4].setRGB(color2, color2, color2);
  586. leds[blinkB + 5].setRGB(color2, color2, color2);
  587. }
  588. if (NUM_LEDS > 150) {
  589. leds[blinkB - 7].setRGB(color2, color2, color2);
  590. leds[blinkB - 8].setRGB(color2, color2, color2);
  591. leds[blinkB + 6].setRGB(color2, color2, color2);
  592. leds[blinkB + 7].setRGB(color2, color2, color2);
  593. }
  594. if (NUM_LEDS > 200) {
  595. leds[blinkB - 9].setRGB(color2, color2, color2);
  596. leds[blinkB - 10].setRGB(color2, color2, color2);
  597. leds[blinkB + 8].setRGB(color2, color2, color2);
  598. leds[blinkB + 9].setRGB(color2, color2, color2);
  599. }
  600. }
  601. }
  602.  
  603. }
  604. }
  605.  
  606. void cops1() {
  607. unsigned long flasherTime1 = millis();
  608. static boolean flashflagg;
  609.  
  610. int ca = 255;
  611. int cb = 255;
  612. byte half = NUM_LEDS / 2;
  613.  
  614. if (flasherTime1 - flasherstart1 >= zSpeed) {
  615.  
  616. flashflagg = ! flashflagg;
  617. flasherstart1 = flasherTime1;
  618. }
  619.  
  620. if (flashflagg == 0) {
  621. ca = 255;
  622. cb = 0;
  623. }
  624. else {
  625. ca = 0;
  626. cb = 255;
  627. }
  628.  
  629. for (int j = 0; j <= half; j++) {
  630. leds[j].setRGB(ca, 0, cb);
  631. }
  632. for (int h = half + 1; h < NUM_LEDS; h++) {
  633. leds[h].setRGB(cb, 0, ca);
  634. }
  635. }
  636.  
  637. void twocolorchase() {
  638. if (once) {
  639. memcpy(zonePattern, twocolorchasepattern, 46);
  640.  
  641. }
  642. for (int i = 0; i < NUM_LEDS; i++) {
  643.  
  644. const unsigned int idx = ( i % 46);
  645. FunctionForEachPixel (i, idx);
  646. CHSV twocolorchaseHSV = colorHSV;
  647.  
  648.  
  649. if (zonePatternA == 0) {
  650. leds[i].setHSV(twocolorchaseHSV.h - 64, twocolorchaseHSV.s, twocolorchaseHSV.v - 30);
  651. }
  652. if (zonePatternA == 1) {
  653. leds[i].setHSV(twocolorchaseHSV.h - 25, twocolorchaseHSV.s, twocolorchaseHSV.v - 30);
  654. }
  655. if (zonePatternA == 2) {
  656. leds[i].setHSV(twocolorchaseHSV.h, twocolorchaseHSV.s, twocolorchaseHSV.v);
  657. }
  658. }
  659. }
  660.  
  661. void bouncing() {
  662. if (once) {
  663. for (int i = 0; i < NUM_LEDS; i++) {
  664. leds[i] = CHSV(64, 128, 16);
  665. }
  666. }
  667. byte color1;
  668. byte color2;
  669. byte color3;
  670.  
  671. //Then off for the next loop around
  672.  
  673.  
  674. for (int i = 0; i < NUM_BALLS; i++) {
  675. if ((pos[i] - 4) <= NUM_LEDS - 1 && (pos[i] - 4) >= 0) {
  676. leds[pos[i] - 4] = CHSV(64, 128, 16);
  677. }
  678. if ((pos[i] - 3) <= NUM_LEDS - 1 && (pos[i] - 3) >= 0) {
  679. leds[pos[i] - 3] = CHSV(64, 128, 16);
  680. }
  681. if ((pos[i] - 2) <= NUM_LEDS - 1 && (pos[i] - 2) >= 0) {
  682. leds[pos[i] - 2] = CHSV(64, 128, 16);
  683. }
  684. if ((pos[i] - 1) <= NUM_LEDS - 1 && (pos[i] - 1) >= 0) {
  685. leds[pos[i] - 1] = CHSV(64, 128, 16);
  686. }
  687. if ((pos[i]) <= NUM_LEDS - 1 && pos[i] >= 0) {
  688. leds[pos[i]] = CHSV(64, 128, 16);
  689. }
  690. if (NUM_LEDS > 100) {
  691. mirror[i] = NUM_LEDS - pos[i];
  692. if ((mirror[i] - 4) <= NUM_LEDS - 1 && (mirror[i] - 4) >= 0) {
  693. leds[mirror[i] - 4] = CHSV(64, 128, 16);
  694. }
  695. if ((mirror[i] - 3) <= NUM_LEDS - 1 && (mirror[i] - 3) >= 0) {
  696. leds[mirror[i] - 3] = CHSV(64, 128, 16);
  697. }
  698. if ((mirror[i] - 2) <= NUM_LEDS - 1 && (mirror[i] - 2) >= 0) {
  699. leds[mirror[i] - 2] = CHSV(64, 128, 16);
  700. }
  701. if ((mirror[i] - 1) <= NUM_LEDS - 1 && (mirror[i] - 1) >= 0) {
  702. leds[mirror[i] - 1] = CHSV(64, 128, 16);
  703. }
  704. if ((mirror[i]) <= NUM_LEDS - 1 && mirror[i] >= 0) {
  705. leds[mirror[i]] = CHSV(64, 128, 16);
  706. }
  707. }
  708. }
  709.  
  710.  
  711.  
  712.  
  713. for (int i = 0; i < NUM_BALLS ; i++) {
  714. tCycle[i] = millis() - tLast[i] ; // Calculate the time since the last time the ball was on the ground
  715.  
  716. // A little kinematics equation calculates positon as a function of time, acceleration (gravity) and intial velocity
  717. h[i] = 0.5 * -2.81 * pow( tCycle[i] / 1000 , 2.0 ) + vImpact[i] * tCycle[i] / 1000;
  718.  
  719. if ( h[i] < 0 ) {
  720. h[i] = 0; // If the ball crossed the threshold of the "ground," put it back on the ground
  721. vImpact[i] = COR[i] * vImpact[i]; // and recalculate its new upward velocity as it's old velocity * COR
  722. tLast[i] = millis();
  723. if ( vImpact[i] < 0.03 ) vImpact[i] = vImpact0; // If the ball is barely moving, "pop" it back up at vImpact0
  724. }
  725. pos[i] = 0 + (round( h[i] * (55) / 3)); // Map "h" to a "pos" integer index position on the LED strip
  726. }
  727. //Choose color of LEDs, then the "pos" LED on
  728.  
  729. for (int i = 0 ; i < NUM_BALLS; i++) {
  730. byte color = 0;
  731. if (i == 0) {
  732. color = 0;
  733. }
  734. if (i == 1) {
  735. color = 106;
  736. }
  737. if (i == 2) {
  738. color = 149;
  739. }
  740.  
  741.  
  742.  
  743. if ((pos[i] - 4) <= NUM_LEDS - 1 && (pos[i] - 4) >= 0) {
  744. leds[pos[i] - 4] = CHSV(colorHSV.h - color, 255, 100);
  745. }
  746. if ((pos[i] - 3) <= NUM_LEDS - 1 && (pos[i] - 3) >= 0) {
  747. leds[pos[i] - 3] = CHSV(colorHSV.h - color, 255, 160);
  748. }
  749. if ((pos[i] - 2) <= NUM_LEDS - 1 && (pos[i] - 2) >= 0) {
  750. leds[pos[i] - 2] = CHSV(colorHSV.h - color, 255, 255);
  751. }
  752. if ((pos[i] - 1) <= NUM_LEDS - 1 && (pos[i] - 1) >= 0) {
  753. leds[pos[i] - 1] = CHSV(colorHSV.h - color, 255, 160);
  754. }
  755. if ((pos[i]) <= NUM_LEDS - 1 && pos[i] >= 0) {
  756. leds[pos[i]] = CHSV(colorHSV.h - color, 255, 100);
  757. }
  758.  
  759. if (NUM_LEDS > 100) {
  760. if (i == 0) {
  761. color = 106;
  762. }
  763. if (i == 1) {
  764. color = 149;
  765. }
  766. if (i == 2) {
  767. color = 0;
  768. }
  769. mirror[i] = NUM_LEDS - pos[i];
  770. if ((mirror[i] - 4) <= NUM_LEDS - 1 && (mirror[i] - 4) >= 0) {
  771. leds[mirror[i] - 4] = CHSV(colorHSV.h - color, 255, 100);
  772. }
  773. if ((mirror[i] - 3) <= NUM_LEDS - 1 && (mirror[i] - 3) >= 0) {
  774. leds[mirror[i] - 3] = CHSV(colorHSV.h - color, 255, 160);
  775. }
  776. if ((mirror[i] - 2) <= NUM_LEDS - 1 && (mirror[i] - 2) >= 0) {
  777. leds[mirror[i] - 2] = CHSV(colorHSV.h - color, 255, 255);
  778. }
  779. if ((mirror[i] - 1) <= NUM_LEDS - 1 && (mirror[i] - 1) >= 0) {
  780. leds[mirror[i] - 1] = CHSV(colorHSV.h - color, 255, 160);
  781. }
  782. if ((mirror[i]) <= NUM_LEDS - 1 && mirror[i] >= 0) {
  783. leds[mirror[i]] = CHSV(colorHSV.h - color, 255, 100);
  784. }
  785. }
  786. }
  787. }
  788.  
  789.  
  790. void strobingC() {
  791. for (int i = 0; i < NUM_LEDS; i++) {
  792. const unsigned int idx = ( i % 46);
  793. FunctionForEachPixel (i, idx);
  794. leds[i] = CHSV(colorHSV.h, colorHSV.s, colorHSV.v * zFlag);
  795. }
  796. }
  797.  
  798. void strobingW() {
  799. for (int i = 0; i < NUM_LEDS; i++) {
  800. const unsigned int idx = ( i % 46);
  801. FunctionForEachPixel (i, idx);
  802. leds[i] = CHSV(0, 0, 255 * zFlag);
  803. }
  804. }
  805.  
  806. void rainbowFade() {
  807. static boolean justonce;
  808. static byte color;
  809. for (int i = 0; i < NUM_LEDS; i++) {
  810. const unsigned int idx = ( i % 46);
  811. FunctionForEachPixel (i, idx);
  812. if (zFlag == 1 && justonce == 1) {
  813. color = color++;
  814. if (color > 255) {
  815. color = 0;
  816. }
  817. justonce = 0;
  818. }
  819. else if (zFlag == 0) {
  820. justonce = 1;
  821. }
  822. leds[i] = CHSV(color, 255, 255);
  823. }
  824. }
  825.  
  826. void redblueFade() {
  827. static boolean justonce;
  828. static byte color = 256;
  829. static int adjuster = -1;
  830. static byte count;
  831.  
  832. for (int i = 0; i < NUM_LEDS; i++) {
  833. const unsigned int idx = ( i % 46);
  834. FunctionForEachPixel (i, idx);
  835. if (zFlag == 1 && justonce == 1) {
  836. if (adjuster < 3) {
  837. color = color + (2 * adjuster);
  838. if (color < 160 && color > 100) {
  839. color = 160;
  840. adjuster = 4;
  841. count = 0;
  842. }
  843. if (color < 3) {
  844. color = 256;
  845. adjuster = 3;
  846. count = 0;
  847. }
  848. }
  849. if (adjuster > 2) {
  850. count = count++;
  851. if (count > 40 && adjuster == 3) {
  852. count = 0;
  853. adjuster = -1;
  854. }
  855. if (count > 40 && adjuster == 4) {
  856. count = 0;
  857. adjuster = 1;
  858. }
  859. }
  860. justonce = 0;
  861. }
  862. else if (zFlag == 0) {
  863. justonce = 1;
  864. }
  865. leds[i] = CHSV(color, 255, 255);
  866. }
  867. }
  868.  
  869. void redgreenFade() {
  870. static boolean justonce;
  871. static byte color = 0;
  872. static int adjuster = 1;
  873. static byte count;
  874.  
  875. for (int i = 0; i < NUM_LEDS; i++) {
  876. const unsigned int idx = ( i % 46);
  877. FunctionForEachPixel (i, idx);
  878. if (zFlag == 1 && justonce == 1) {
  879. if (adjuster < 3) {
  880. color = color + (2 * adjuster);
  881. if (color > 96 && color < 200) {
  882. color = 96;
  883. adjuster = 4;
  884. count = 0;
  885. }
  886. if (color < 0 || color > 200) {
  887. color = 0;
  888. adjuster = 3;
  889. count = 0;
  890. }
  891. }
  892. if (adjuster > 2) {
  893. count = count++;
  894. if (count > 40 && adjuster == 3) {
  895. count = 0;
  896. adjuster = 1;
  897. }
  898. if (count > 40 && adjuster == 4) {
  899. count = 0;
  900. adjuster = -1;
  901. }
  902. }
  903. justonce = 0;
  904. }
  905. else if (zFlag == 0) {
  906. justonce = 1;
  907. }
  908. leds[i] = CHSV(color, 255, 255);
  909. }
  910. }
  911.  
  912. void purpleorangeFade() {
  913. static boolean justonce;
  914. static byte color = 210;
  915. static int adjuster = 1;
  916. static byte count;
  917. static byte ccount;
  918.  
  919. for (int i = 0; i < NUM_LEDS; i++) {
  920.  
  921. const unsigned int idx = ( i % 46);
  922. FunctionForEachPixel (i, idx);
  923.  
  924. if (zFlag == 1 && justonce == 1) {
  925.  
  926. if (adjuster < 3) {
  927. ccount++;
  928. if (ccount > 2) {
  929. color = color + adjuster;
  930. ccount == 0;
  931. }
  932. if (color > 9 && color < 210) {
  933. adjuster = 3;
  934. }
  935. }
  936. if (adjuster > 2) {
  937. count++;
  938. if (count > 75 && adjuster == 3) {
  939. count = 0;
  940. if (color > 9 && color < 50) {
  941. adjuster = -1;
  942. color = 9;
  943. }
  944. if (color < 210 && color > 50) {
  945. adjuster = 1;
  946. color = 210;
  947. }
  948. }
  949. }
  950. justonce = 0;
  951. }
  952. else if (zFlag == 0) {
  953. justonce = 1;
  954. }
  955. leds[i] = CHSV(color, 255, 255);
  956. }
  957. }
  958.  
  959. void aquaFade() {
  960. static boolean justonce;
  961. static byte color = 100;
  962. static int adjuster = 1;
  963. static byte count;
  964. static byte ccount;
  965. static int sAdjuster = -10;
  966. static int saturate = 255;
  967.  
  968.  
  969. for (int i = 0; i < NUM_LEDS; i++) {
  970.  
  971. const unsigned int idx = ( i % 46);
  972. FunctionForEachPixel (i, idx);
  973. if (zFlag == 1 && justonce == 1) {
  974.  
  975. if (adjuster < 3) {
  976. ccount++;
  977. if (ccount > 2) {
  978. color = color + adjuster;
  979. ccount == 0;
  980. }
  981. if (color > 150 || color < 100) {
  982. adjuster = 3;
  983. }
  984. }
  985. if (adjuster > 2) {
  986. count++;
  987. if (adjuster == 3) {
  988. if (color > 150) {
  989. adjuster = 4;
  990. color = 150;
  991. }
  992. if (color < 100 && count > 75) {
  993. count = 0;
  994. adjuster = 1;
  995. color = 100;
  996. }
  997. }
  998. }
  999. if (adjuster == 4) {
  1000. saturate = saturate + sAdjuster;
  1001. if (saturate < 50) {
  1002. sAdjuster = 10;
  1003. saturate = 50;
  1004. }
  1005. else if (saturate > 255) {
  1006. sAdjuster = -10;
  1007. saturate = 255;
  1008. adjuster = -1;
  1009. }
  1010. }
  1011. justonce = 0;
  1012. }
  1013. else if (zFlag == 0) {
  1014. justonce = 1;
  1015. }
  1016. leds[i] = CHSV(color, saturate, 255);
  1017. }
  1018. }
  1019.  
  1020. void skyFade() {
  1021. static boolean justonce;
  1022. static byte color = 130;
  1023. static int adjuster = -1;
  1024. static byte ccount;
  1025. static int sAdjuster = -10;
  1026. static int saturate = 255;
  1027.  
  1028. for (int i = 0; i < NUM_LEDS; i++) {
  1029.  
  1030. const unsigned int idx = ( i % 46);
  1031. FunctionForEachPixel (i, idx);
  1032.  
  1033. if (zFlag == 1 && justonce == 1) {
  1034.  
  1035. if (adjuster < 3) {
  1036. ccount++;
  1037. if (ccount > 2) {
  1038. color = color + adjuster;
  1039. ccount == 0;
  1040. }
  1041. if (color > 180 || color < 130) {
  1042. adjuster = 3;
  1043. }
  1044. }
  1045. if (adjuster == 3) {
  1046. if (color > 180) {
  1047. adjuster = 4;
  1048. color = 180;
  1049. }
  1050. if (color < 130) {
  1051. adjuster = 4;
  1052. color = 130;
  1053. }
  1054. }
  1055. if (adjuster == 4) {
  1056. saturate = saturate + sAdjuster;
  1057. if (saturate < 100) {
  1058. sAdjuster = 10;
  1059. saturate = 100;
  1060. }
  1061. else if (saturate > 255) {
  1062. sAdjuster = -10;
  1063. saturate = 255;
  1064. if (color == 180) {
  1065. adjuster = -1;
  1066. }
  1067. if (color == 130) {
  1068. adjuster = 1;
  1069. }
  1070. }
  1071. }
  1072. justonce = 0;
  1073. }
  1074. else if (zFlag == 0) {
  1075. justonce = 1;
  1076. }
  1077. leds[i] = CHSV(color, saturate, 255);
  1078. }
  1079. }
  1080.  
  1081. void everyFade() {
  1082. static boolean justonce;
  1083. static byte color = 0;
  1084. static byte saturation = 255;
  1085. static byte value = 100;
  1086. static int adjuster = 1;
  1087. static byte up = 0;
  1088.  
  1089. for (int i = 0; i < NUM_LEDS; i++) {
  1090.  
  1091. const unsigned int idx = ( i % 46);
  1092. FunctionForEachPixel (i, idx);
  1093. if (zFlag == 1 && justonce == 1) {
  1094. if (up == 0) {
  1095. color = color + adjuster;
  1096. if (color == 255) {
  1097. if (value < 255) {
  1098. value = value + adjuster;
  1099. }
  1100. if (value == 255) {
  1101. saturation = saturation - adjuster;
  1102. if (saturation == 100) {
  1103. up = 1;
  1104. }
  1105. }
  1106. }
  1107. }
  1108. if (up == 1) {
  1109. color = color - adjuster;
  1110.  
  1111. if (color == 255) {
  1112. if (saturation < 255) {
  1113. saturation = saturation + adjuster;
  1114. }
  1115. if (saturation == 255) {
  1116. value = value - adjuster;
  1117. if (value == 100) {
  1118. up = 1;
  1119. }
  1120. }
  1121. }
  1122. }
  1123. justonce = 0;
  1124. }
  1125.  
  1126. else if (zFlag == 0) {
  1127. justonce = 1;
  1128. }
  1129. leds[i] = CHSV(color, saturation, value);
  1130. }
  1131. }
  1132.  
  1133. void veryslowFade() {
  1134. static boolean justonce;
  1135. if (once) {
  1136. colorHSV.h = random(0, 255);
  1137. zSpeed = 900000;
  1138. }
  1139.  
  1140. for (int i = 0; i < NUM_LEDS; i++) {
  1141.  
  1142. const unsigned int idx = ( i % 46);
  1143. FunctionForEachPixel (i, idx);
  1144. if (zFlag == 1 && justonce == 1) {
  1145. colorHSV.h++;
  1146. justonce = 0;
  1147. }
  1148. else if (zFlag == 0) {
  1149. justonce = 1;
  1150. }
  1151. leds[i] = CHSV(colorHSV.h, 255, 255);
  1152. }
  1153. }
  1154.  
  1155. void twinkle() {
  1156.  
  1157. int ranamount = 250; // The higher the number, lowers the chance for a pixel to light up. // Standard delay value in milliseconds.
  1158. uint8_t fadeval = 255; // Fade rate
  1159.  
  1160.  
  1161. //if (ranamount >NUM_LEDS) ranamount = NUM_LEDS; // Make sure we're at least utilizing ALL the LED's.
  1162. int idex = random16(0, ranamount);
  1163. if (idex < NUM_LEDS) { // Only the lowest probability twinkles will do.
  1164. leds[idex] = random(); // The idex LED is set to a random 32 bit value
  1165. }
  1166.  
  1167. for (int i = 0; i < NUM_LEDS; i++) {
  1168.  
  1169. const unsigned int idx = ( i % 46);
  1170. FunctionForEachPixel (i, idx);
  1171. leds[i].nscale8(fadeval); // Go through the array and reduce each RGB value by a percentage.
  1172.  
  1173. }
  1174. }
  1175.  
  1176.  
  1177. void randomWalk() {
  1178. static boolean justonce;
  1179. static boolean resetflag;
  1180. static int center;
  1181. static int newpos = 999;
  1182. static byte color;
  1183. int adjuster;
  1184. byte randoms;
  1185.  
  1186. if (once) {
  1187. resetflag = 1;
  1188. zFlag = 1;
  1189. justonce = 1;
  1190. }
  1191.  
  1192. center = (NUM_LEDS / 2) - 6;
  1193.  
  1194.  
  1195. randoms = rand();
  1196. if (randoms < 128) {
  1197. adjuster = -1;
  1198. }
  1199. else adjuster = 1;
  1200.  
  1201.  
  1202. if (zFlag == 1 && justonce == 1) {
  1203. justonce = 0;
  1204. if (resetflag == 1) {
  1205. newpos = center ;
  1206. color = rand();
  1207. resetflag = 0;
  1208. }
  1209. else {
  1210. color = color + 1;
  1211. newpos = newpos + adjuster ;
  1212. }
  1213.  
  1214. if ((newpos) < 0 || (newpos - 6) > NUM_LEDS ) {
  1215. resetflag = 1;
  1216. }
  1217. }
  1218. else if (zFlag == 0) {
  1219. justonce = 1;
  1220. }
  1221.  
  1222. for (int i = 0; i < NUM_LEDS; i++) {
  1223. leds[i] = CHSV(color - 90, 255, 50);
  1224. }
  1225.  
  1226. if (NUM_LEDS > 100) {
  1227. if ((newpos - 9) < NUM_LEDS && (newpos - 9) >= 0) {
  1228. leds[newpos - 9] = CHSV(color, 255, 100);
  1229. }
  1230. if ((newpos - 8) < NUM_LEDS && (newpos - 8) >= 0) {
  1231. leds[newpos - 8] = CHSV(color, 255, 140);
  1232. }
  1233. if ((newpos - 7) < NUM_LEDS && (newpos - 7) >= 0) {
  1234. leds[newpos - 7] = CHSV(color, 255, 170);
  1235. }
  1236. if ((newpos - 6) < NUM_LEDS && (newpos - 6) >= 0) {
  1237. leds[newpos - 6] = CHSV(color, 255, 190);
  1238. }
  1239. if (newpos - 5 < NUM_LEDS && newpos - 5 >= 0) {
  1240. leds[newpos - 5] = CHSV(color, 255, 255);
  1241. }
  1242. if ((newpos - 4) < NUM_LEDS && (newpos - 4) >= 0) {
  1243. leds[newpos - 4] = CHSV(color, 255, 255);
  1244. }
  1245. if ((newpos - 3) < NUM_LEDS && (newpos - 3) >= 0) {
  1246. leds[newpos - 3] = CHSV(color, 255, 190);
  1247. }
  1248. if ((newpos - 2) < NUM_LEDS && (newpos - 2) >= 0) {
  1249. leds[newpos - 2] = CHSV(color, 255, 170);
  1250. }
  1251. if ((newpos - 1) < NUM_LEDS && (newpos - 1) >= 0) {
  1252. leds[newpos - 1] = CHSV(color, 255, 140);
  1253. }
  1254. if (newpos < NUM_LEDS && newpos >= 0) {
  1255. leds[newpos] = CHSV(color, 255, 100);
  1256. }
  1257. }
  1258. else {
  1259. if ((newpos - 4) < NUM_LEDS && (newpos - 4) >= 0) {
  1260. leds[newpos - 4] = CHSV(color, 255, 100);
  1261. }
  1262. if ((newpos - 3) < NUM_LEDS && (newpos - 3) >= 0) {
  1263. leds[newpos - 3] = CHSV(color, 255, 160);
  1264. }
  1265. if ((newpos - 2) < NUM_LEDS && (newpos - 2) >= 0) {
  1266. leds[newpos - 2] = CHSV(color, 255, 255);
  1267. }
  1268. if ((newpos - 1) < NUM_LEDS && (newpos - 1) >= 0) {
  1269. leds[newpos - 1] = CHSV(color, 255, 160);
  1270. }
  1271. if (newpos < NUM_LEDS && newpos >= 0) {
  1272. leds[newpos] = CHSV(color, 255, 100);
  1273. }
  1274. }
  1275.  
  1276. }
  1277.  
  1278. void colorrandomWalk() {
  1279. static boolean justonce;
  1280. static boolean resetflag;
  1281. static int center;
  1282. static int newpos = 999;
  1283. static byte color;
  1284. int adjuster;
  1285. byte randoms;
  1286. if (once) {
  1287. resetflag = 1;
  1288. zFlag = 1;
  1289. justonce = 1;
  1290. }
  1291.  
  1292. center = (NUM_LEDS / 2) - 6;
  1293.  
  1294.  
  1295. randoms = rand();
  1296. if (randoms < 128) {
  1297. adjuster = -1;
  1298. }
  1299. else adjuster = 1;
  1300.  
  1301.  
  1302. if (zFlag == 1 && justonce == 1) {
  1303. justonce = 0;
  1304. if (resetflag == 1) {
  1305. newpos = center ;
  1306. color = colorHSV.h - 90;
  1307. resetflag = 0;
  1308. }
  1309. else {
  1310. newpos = newpos + adjuster ;
  1311. }
  1312.  
  1313. if ((newpos) < 0 || (newpos - 6) > NUM_LEDS ) {
  1314. resetflag = 1;
  1315. }
  1316. }
  1317. else if (zFlag == 0) {
  1318. justonce = 1;
  1319. }
  1320.  
  1321. for (int i = 0; i < NUM_LEDS; i++) {
  1322. leds[i] = CHSV(color, 255, 50);
  1323. }
  1324.  
  1325. if (NUM_LEDS > 100) {
  1326. if ((newpos - 9) < NUM_LEDS && (newpos - 9) >= 0) {
  1327. leds[newpos - 9] = CHSV(colorHSV.h, 255, 100);
  1328. }
  1329. if ((newpos - 8) < NUM_LEDS && (newpos - 8) >= 0) {
  1330. leds[newpos - 8] = CHSV(colorHSV.h, 255, 140);
  1331. }
  1332. if ((newpos - 7) < NUM_LEDS && (newpos - 7) >= 0) {
  1333. leds[newpos - 7] = CHSV(colorHSV.h, 255, 170);
  1334. }
  1335. if ((newpos - 6) < NUM_LEDS && (newpos - 6) >= 0) {
  1336. leds[newpos - 6] = CHSV(colorHSV.h, 255, 190);
  1337. }
  1338. if (newpos - 5 < NUM_LEDS && newpos - 5 >= 0) {
  1339. leds[newpos - 5] = CHSV(colorHSV.h, 255, 255);
  1340. }
  1341. if ((newpos - 4) < NUM_LEDS && (newpos - 4) >= 0) {
  1342. leds[newpos - 4] = CHSV(colorHSV.h, 255, 255);
  1343. }
  1344. if ((newpos - 3) < NUM_LEDS && (newpos - 3) >= 0) {
  1345. leds[newpos - 3] = CHSV(colorHSV.h, 255, 190);
  1346. }
  1347. if ((newpos - 2) < NUM_LEDS && (newpos - 2) >= 0) {
  1348. leds[newpos - 2] = CHSV(colorHSV.h, 255, 170);
  1349. }
  1350. if ((newpos - 1) < NUM_LEDS && (newpos - 1) >= 0) {
  1351. leds[newpos - 1] = CHSV(colorHSV.h, 255, 140);
  1352. }
  1353. if (newpos < NUM_LEDS && newpos >= 0) {
  1354. leds[newpos] = CHSV(colorHSV.h, 255, 100);
  1355. }
  1356. }
  1357. else {
  1358. if ((newpos - 4) < NUM_LEDS && (newpos - 4) >= 0) {
  1359. leds[newpos - 4] = CHSV(colorHSV.h, 255, 100);
  1360. }
  1361. if ((newpos - 3) < NUM_LEDS && (newpos - 3) >= 0) {
  1362. leds[newpos - 3] = CHSV(colorHSV.h, 255, 160);
  1363. }
  1364. if ((newpos - 2) < NUM_LEDS && (newpos - 2) >= 0) {
  1365. leds[newpos - 2] = CHSV(colorHSV.h, 255, 255);
  1366. }
  1367. if ((newpos - 1) < NUM_LEDS && (newpos - 1) >= 0) {
  1368. leds[newpos - 1] = CHSV(colorHSV.h, 255, 160);
  1369. }
  1370. if (newpos < NUM_LEDS && newpos >= 0) {
  1371. leds[newpos] = CHSV(colorHSV.h, 255, 100);
  1372. }
  1373. }
  1374.  
  1375. }
  1376.  
  1377. void specialrandomWalk() {
  1378. static boolean justonce;
  1379. static boolean resetflag;
  1380. static int center;
  1381. static int newPos = 999;
  1382. static byte color;
  1383. int adjuster;
  1384. byte randoms;
  1385.  
  1386. if (once) {
  1387. resetflag = 1;
  1388. zFlag = 1;
  1389. justonce = 1;
  1390. }
  1391.  
  1392.  
  1393. center = (NUM_LEDS / 2) - 6;
  1394.  
  1395. randoms = rand();
  1396. if (randoms < 128) {
  1397. adjuster = -1;
  1398. }
  1399. else adjuster = 1;
  1400.  
  1401.  
  1402. for (int i = 0; i < NUM_LEDS; i++) {
  1403. FunctionForEachPixel (i, 1);
  1404. }
  1405.  
  1406. if (zFlag == 1 && justonce == 1) {
  1407.  
  1408. justonce = 0;
  1409. if (resetflag == 1) {
  1410. newPos = center;
  1411. if (randoms < 128) {
  1412. if (colorSF == 0) color = 96;
  1413. if (colorSF == 160) color = 0;
  1414. if (colorSF == 17) color = 210;
  1415. }
  1416. else {
  1417. if (colorSF == 0) {
  1418. color = colorSF;
  1419. colorSF = 96;
  1420. }
  1421. if (colorSF == 160) {
  1422. color = colorSF;
  1423. colorSF = 0;
  1424. }
  1425. if (colorSF == 17) {
  1426. color = colorSF;
  1427. colorSF = 210;
  1428. }
  1429. }
  1430. resetflag = 0;
  1431. }
  1432. else {
  1433. newPos = newPos + adjuster;
  1434. }
  1435.  
  1436. if ((newPos) < -6 || newPos > NUM_LEDS) {
  1437. resetflag = 1;
  1438. if (colorSF == 160 || color == 160)
  1439. {
  1440. colorSF = 160;
  1441. }
  1442. }
  1443. }
  1444. else if (zFlag == 0) {
  1445. justonce = 1;
  1446. }
  1447.  
  1448. for (int i = 0; i < NUM_LEDS; i++) {
  1449.  
  1450. const unsigned int idx = ( i % 46);
  1451. FunctionForEachPixel (i, idx);
  1452.  
  1453. leds[i] = CHSV(color, 255, 50);
  1454. }
  1455.  
  1456. if (newPos >= 0 && newPos <= NUM_LEDS) {
  1457. leds[newPos] = CHSV(colorSF, 255, 50);
  1458. }
  1459. if (newPos + 1 >= 0 && newPos + 1 <= NUM_LEDS) {
  1460. leds[newPos + 1] = CHSV(colorSF, 255, 100);
  1461. }
  1462. if (newPos + 2 >= 0 && newPos + 2 <= NUM_LEDS) {
  1463. leds[newPos + 2] = CHSV(colorSF, 255, 175);
  1464. }
  1465. if (newPos + 3 >= 0 && newPos + 3 <= NUM_LEDS) {
  1466. if (colorSF == 160 || color == 160) {
  1467. leds[newPos + 3] = CHSV(0, 0, 255);
  1468. }
  1469. else leds[newPos + 3] = CHSV(colorSF, 255, 255);
  1470. }
  1471. if (newPos + 4 >= 0 && newPos + 4 <= NUM_LEDS) {
  1472. leds[newPos + 4] = CHSV(colorSF, 255, 175);
  1473. }
  1474. if (newPos + 5 >= 0 && newPos + 5 <= NUM_LEDS) {
  1475. leds[newPos + 5] = CHSV(colorSF, 255, 100);
  1476. }
  1477. if (newPos + 6 >= 0 && newPos + 6 <= NUM_LEDS) {
  1478. leds[newPos + 6] = CHSV(colorSF, 255, 50 );
  1479. }
  1480. }
  1481.  
  1482. void patrioticTwinkle() {
  1483. zSpeed = 100;
  1484. int ranamount = 1000; // The higher the number, lowers the chance for a pixel to light up. // Standard delay value in milliseconds.
  1485. byte fadeval = 255; // Fade rate
  1486. static byte color;
  1487. static boolean justonce;
  1488.  
  1489. //if (ranamount >NUM_LEDS) ranamount = NUM_LEDS; // Make sure we're at least utilizing ALL the LED's.
  1490. int idex = random16(0, ranamount);
  1491.  
  1492. if (idex < NUM_LEDS) { // Only the lowest probability twinkles will do.
  1493. byte value = random(100, 255);
  1494. byte saturation = random();
  1495. if (color == 160) {
  1496. color = 0;
  1497. }
  1498. else color = 160;
  1499. if(idex < NUM_LEDS && idex > 0){
  1500. leds[idex] = CHSV(color, saturation, value);
  1501. }
  1502. if((idex + 1) < NUM_LEDS && (idex + 1) > 0){
  1503. leds[idex + 1] = CHSV(color, saturation, value);
  1504. }
  1505. }
  1506. if (zFlag == 1 && justonce == 1) {
  1507. justonce = 0;
  1508. for (int i = 0; i < NUM_LEDS; i++) {
  1509. leds[i].nscale8(fadeval); // Go through the array and reduce each RGB value by a percentage.
  1510. if((i + 1) < NUM_LEDS && (i + 1) > 0){
  1511. leds[i + 1].nscale8(fadeval);
  1512. }
  1513. }
  1514. } else if (zFlag == 0) {
  1515. justonce = 1;
  1516. }
  1517. }
  1518.  
  1519. void christmasTwinkle() {}
  1520. /* zSpeed = 100;
  1521. int ranamount = 1000; // The higher the number, lowers the chance for a pixel to light up. // Standard delay value in milliseconds.
  1522. byte fadeval = 255; // Fade rate
  1523. static byte color;
  1524. static boolean justonce;
  1525.  
  1526. // Make sure we're at least utilizing ALL the LED's.
  1527. int idex = random16(0, ranamount);
  1528.  
  1529. if (idex < NUM_LEDS) { // Only the lowest probability twinkles will do.
  1530. byte value = random(100, 255);
  1531. byte saturation = random();
  1532. if (color == 0) {
  1533. color = 96;
  1534. }
  1535. else color = 0;
  1536.  
  1537. if(idex < NUM_LEDS && idex > 0){
  1538. leds[idex] = CHSV(color, saturation, value);
  1539. }
  1540. if((idex + 1) < NUM_LEDS && (idex + 1) > 0){
  1541. leds[idex + 1] = CHSV(color, saturation, value);
  1542. }
  1543. }
  1544. if (zFlag == 1 && justonce == 1) {
  1545. justonce = 0;
  1546. for (int i = 0; i < NUM_LEDS; i++) {
  1547. leds[i].nscale8(fadeval); // Go through the array and reduce each RGB value by a percentage.
  1548. if((i + 1) < NUM_LEDS && (i + 1) > 0){
  1549. leds[i + 1].nscale8(fadeval);
  1550. }
  1551. }
  1552. } else if (zFlag == 0) {
  1553. justonce = 1;
  1554. }
  1555. }
  1556. */
  1557.  
  1558. void colorChase() {
  1559. if (once) {
  1560. memcpy(zonePattern, colorchasepattern, 46);
  1561. once = 0;
  1562. }
  1563. byte color;
  1564. byte color2;
  1565. byte thecolor;
  1566. byte thesaturation;
  1567. static boolean justonce;
  1568. static unsigned int count;
  1569. static byte oldColor;
  1570. static byte newColor;
  1571.  
  1572.  
  1573. for (int i = 0; i < NUM_LEDS; i++) {
  1574. const unsigned int idx = ( i % 46);
  1575. FunctionForEachPixel (i, idx);
  1576. int value = 100000 * 1 / (zSpeedA);
  1577. Serial.println(value);
  1578. if (zFlag == 1 && justonce == 1) {
  1579. justonce = 0;
  1580. count++;
  1581. if (count > value || oldColor == newColor) {
  1582.  
  1583. oldColor = newColor;
  1584. newColor = oldColor + random(30, 200);
  1585. count = 0;
  1586. }
  1587. }
  1588. else if (zFlag == 0) {
  1589. justonce = 1;
  1590. }
  1591. switch (colorSF) {
  1592. case 1:
  1593. thesaturation = 255;
  1594. if (zonePatternA == 0 || zonePatternA == 1) {
  1595. thecolor = 0;
  1596. }
  1597. else thecolor = 96;
  1598. break;
  1599. case 2:
  1600. if (zonePattern == 0) {
  1601. thecolor = 0;
  1602. thesaturation = 255;
  1603. }
  1604. if (zonePatternA == 1 || zonePatternA == 2) {
  1605. thecolor = 0;
  1606. thesaturation = 0;
  1607. }
  1608. if (zonePatternA == 3) {
  1609. thecolor = 160;
  1610. thesaturation = 255;
  1611. }
  1612. break;
  1613. case 3:
  1614. thesaturation = 255;
  1615. if (zonePatternA == 0 || zonePatternA == 1) {
  1616. thecolor = 13;
  1617. }
  1618. else thecolor = 210;
  1619. break;
  1620. case 4:
  1621. thesaturation = 255;
  1622. if (zonePatternA == 0 || zonePatternA == 1) {
  1623. thecolor = oldColor;
  1624. }
  1625. else {
  1626. thecolor = newColor;
  1627. }
  1628. break;
  1629.  
  1630. }
  1631.  
  1632. leds[i] = CHSV(thecolor, thesaturation, 255);
  1633.  
  1634. }
  1635. }
  1636.  
  1637.  
  1638.  
  1639. void colorslide() {
  1640. if (once) {
  1641. if (DisplaySpeed == 0) {
  1642. zSpeed = 50;
  1643. }
  1644. else if (DisplaySpeed == 1) {
  1645. zSpeed = 45;
  1646. }
  1647. else if (DisplaySpeed == 2) {
  1648. zSpeed = 40;
  1649. }
  1650. else if (DisplaySpeed == 3) {
  1651. zSpeed = 35;
  1652. }
  1653. else if (DisplaySpeed == 4) {
  1654. zSpeed = 30;
  1655. }
  1656. else if (DisplaySpeed == 5) {
  1657. zSpeed = 25;
  1658. }
  1659. else if (DisplaySpeed == 6) {
  1660. zSpeed = 20;
  1661. }
  1662. else if (DisplaySpeed == 7) {
  1663. zSpeed = 15;
  1664. }
  1665. else if (DisplaySpeed == 8) {
  1666. zSpeed = 10;
  1667. }
  1668. else if (DisplaySpeed == 9) {
  1669. zSpeed = 5;
  1670. }
  1671. else if (DisplaySpeed == 10) {
  1672. zSpeed = 2;
  1673. }
  1674. }
  1675. static boolean justonce;
  1676. static boolean colorF;
  1677. static byte count;
  1678. static byte color;
  1679. static byte saturation;
  1680. static byte value0;
  1681.  
  1682. for (int i = 0; i < NUM_LEDS; i++) {
  1683. if (zFlag == 1 && justonce == 1) {
  1684. if (count < NUM_LEDS && count >= 0) {
  1685. count++;
  1686. }
  1687. else {
  1688. count = 0;
  1689. colorF = 1;
  1690. }
  1691. switch (colorSF) {
  1692. case 1:
  1693. if (colorF == 1) {
  1694. colorF = 0;
  1695. color = random();
  1696. saturation = random(100, 255);
  1697. value = random(100, 255);
  1698.  
  1699. }
  1700. case 2:
  1701. if (colorF == 1) {
  1702. colorF = 0;
  1703. color = random();
  1704. saturation = 255;
  1705. value = 255;
  1706.  
  1707. }
  1708. break;
  1709. case 3:
  1710. saturation = 255;
  1711. value = 255;
  1712. color = random();
  1713. break;
  1714.  
  1715. case 4:
  1716. if (colorF == 1) {
  1717. colorF = 0;
  1718. if (color == 0 && saturation == 255) {
  1719. saturation = 0;
  1720. value = 255;
  1721. }
  1722. else if (saturation == 0 && color == 0) {
  1723. saturation = 255;
  1724. value = 255;
  1725. color = 160;
  1726. }
  1727. else if (color == 160) {
  1728. color = 0;
  1729. saturation = 255;
  1730. value = 255;
  1731. }
  1732. else color = 0;
  1733. }
  1734. break;
  1735. case 5:
  1736. if (colorF == 1) {
  1737. colorF = 0;
  1738. saturation = 255;
  1739. value = 255;
  1740. if (color == 215) {
  1741. color = 85;
  1742. }
  1743. else if (color == 85) {
  1744. color = 139;
  1745. }
  1746. else if (color == 139) {
  1747. color = 64;
  1748. }
  1749. else if (color == 64) {
  1750. color = 215;
  1751. }
  1752. else color = 215;
  1753. }
  1754. break;
  1755. case 6:
  1756. if (colorF == 1) {
  1757. colorF = 0;
  1758. saturation = 255;
  1759. value = 255;
  1760. if (color == 200) {
  1761. color = 16;
  1762. }
  1763. else if (color == 16) {
  1764. color = 200;
  1765.  
  1766. }
  1767. else color = 200;
  1768. break;
  1769. case 7:
  1770. if (colorF == 1) {
  1771. colorF = 0;
  1772. saturation = 255;
  1773. value = 255;
  1774. if (color == 0) {
  1775. color = 96;
  1776. }
  1777. else if (color == 96) {
  1778. color = 0;
  1779.  
  1780. }
  1781. else color = 0;
  1782. }
  1783. break;
  1784. }
  1785. }
  1786. justonce = 0;
  1787. }
  1788. else if (zFlag == 0) {
  1789. justonce = 1;
  1790. }
  1791. if (count < NUM_LEDS && count >= 0) {
  1792. leds[count] = CHSV(color, saturation, value);
  1793. }
  1794. }
  1795. }
  1796.  
  1797.  
  1798.  
  1799.  
  1800. void rainDrop() {
  1801. static boolean justonce;
  1802. static byte count;
  1803. static byte color;
  1804. static boolean resetF;
  1805. static byte saturation = 255;
  1806. static byte value;
  1807. static int droplet;
  1808. static boolean flag2;
  1809. static boolean modA = 1;
  1810. static byte count2;
  1811. static byte randombyte;
  1812. if (once) {
  1813. zSpeed = 2;
  1814. once = 0;
  1815. }
  1816. if (resetF == 0) {
  1817. droplet = NUM_LEDS - 2;
  1818. resetF = 1;
  1819. modA = 1;
  1820. value = 25;
  1821. randombyte = random(0, 2);
  1822.  
  1823. switch (colorSF) {
  1824. case 1:
  1825. {
  1826. color = random(0, 255);
  1827. int satr = random(0, 10);
  1828. if (satr < 2) {
  1829. saturation = random(0, 255);
  1830. } else saturation = 255;
  1831. break;
  1832. }
  1833. case 2:
  1834. {
  1835. color = 160;
  1836. saturation = 25;
  1837. randombyte = 3;
  1838. break;
  1839. case 3:
  1840. color = 160;
  1841. saturation = 160 + random(0, 25);
  1842. randombyte = 2;
  1843. break;
  1844. }
  1845. case 4:
  1846. {
  1847. saturation = 255;
  1848. if (color == 96) {
  1849. color = 0;
  1850. }
  1851. else if (color == 0) {
  1852. color = 96;
  1853. } else color = 0;
  1854. break;
  1855. }
  1856. case 5:
  1857. {
  1858. if (color == 160) {
  1859. color = 0;
  1860. saturation = 255;
  1861. }
  1862. else if (color == 0 && saturation == 255) {
  1863. saturation = 0;
  1864. }
  1865. else if (color == 0 && saturation == 0) {
  1866. color = 160;
  1867. saturation = 255;
  1868. }
  1869. else color = 0;
  1870. break;
  1871. }
  1872. case 6:
  1873. {
  1874. saturation = 255;
  1875. if (color == 215) {
  1876. color = 85;
  1877. }
  1878. else if (color == 85) {
  1879. color = 139;
  1880. }
  1881. else if (color == 139) {
  1882. color = 64;
  1883. }
  1884. else if (color == 64) {
  1885. color = 215;
  1886. }
  1887. else color = 215;
  1888. break;
  1889. }
  1890. case 7:
  1891. {
  1892. saturation = colorHSV.s;
  1893. color = colorHSV.h;
  1894. break;
  1895. }
  1896. }
  1897. }
  1898.  
  1899. if (value < 254 && (droplet + 2) >= 0) {
  1900. value++;
  1901. count = 0;
  1902. }
  1903.  
  1904. if (value == 254 && count < 56) {
  1905. if (zFlag == 1 && justonce == 1) {
  1906. justonce = 0;
  1907. count++;
  1908. }
  1909. else if (zFlag == 0) {
  1910. justonce = 1;
  1911. }
  1912. }
  1913.  
  1914. if (count > 55) {
  1915. if (droplet + 2 >= 0 && flag2 == 0) {
  1916. //droplet = droplet - 1;
  1917. modA = 0;
  1918. flag2 = 1;
  1919. }
  1920. else if (flag2 == 1 && count < 225) {
  1921. count++;
  1922. if (count > 75 && droplet + 2 >= 0) {
  1923. count = 200;
  1924. count2++;
  1925. if (count2 > randombyte) {
  1926. count2 = 0;
  1927. droplet = droplet - 1;
  1928. }
  1929. }
  1930. }
  1931. }
  1932. if (droplet + 2 <= 0) {
  1933. flag2 = 0;
  1934. value = 50;
  1935. count = 0;
  1936. resetF = 0;
  1937. }
  1938.  
  1939.  
  1940. for (int i = 0; i < NUM_LEDS; i++) {
  1941. if ((droplet - 2) >= 0 && (droplet - 2) < NUM_LEDS) {
  1942. leds[droplet - 2] = CHSV(color, saturation, 0);
  1943. }
  1944. if ((droplet - 1) >= 0 && (droplet - 1) < NUM_LEDS) {
  1945. leds[droplet - 1] = CHSV(color, saturation, value >> modA);
  1946. }
  1947. if ((droplet) >= 0 && (droplet) < NUM_LEDS) {
  1948. leds[droplet] = CHSV(color, saturation, value);
  1949. }
  1950. if ((droplet + 1) >= 0 && (droplet + 1) < NUM_LEDS) {
  1951. leds[droplet + 1] = CHSV(color, saturation, value >> 1);
  1952. }
  1953. if ((droplet + 2) >= 0 && (droplet + 2) < NUM_LEDS) {
  1954. leds[droplet + 2] = CHSV(color, saturation, 0);
  1955. }
  1956. }
  1957. }
  1958.  
  1959. void colorWhipe() {
  1960.  
  1961. static boolean justonce;
  1962. static byte count;
  1963. static byte color = 87;
  1964. static byte saturation = 255;
  1965. static byte bgcolor = 160;
  1966. static byte currentpixel;
  1967. static boolean resetF;
  1968. static byte bgsaturation = 255;
  1969. static byte flip = 1;
  1970. byte modA;
  1971. if (once) {
  1972. resetF = 0;
  1973. flip = 1;
  1974. }
  1975.  
  1976. if (resetF == 0) {
  1977.  
  1978. if (colorSF == 1) {
  1979. bgcolor = color;
  1980. color = rand();
  1981. saturation = 255;
  1982. bgsaturation = 255;
  1983. }
  1984. if (colorSF == 2) {
  1985. if (flip == 1) {
  1986. color = colorHSV.h;
  1987. saturation = colorHSV.s;
  1988. bgcolor = colorHSV.h - 90;
  1989. bgsaturation = colorHSV.s;
  1990. flip = 0;
  1991. } else {
  1992. color = colorHSV.h - 90;
  1993. saturation = colorHSV.s;
  1994. bgcolor = colorHSV.h;
  1995. bgsaturation = colorHSV.s;
  1996. flip = 1;
  1997. }
  1998. }
  1999. if (colorSF == 3) {
  2000. if (flip == 1) {
  2001. color = 0;
  2002. saturation = 255;
  2003. bgcolor = 96;
  2004. bgsaturation = 255;
  2005. flip = 2;
  2006. } else if (flip == 2) {
  2007. color = 96;
  2008. saturation = 255;
  2009. bgcolor = 0;
  2010. bgsaturation = 255;
  2011. flip = 1;
  2012. }
  2013. }
  2014. if (colorSF == 4) {
  2015. if (flip == 1) {
  2016. color = 0;
  2017. saturation = 255;
  2018. bgcolor = 160;
  2019. bgsaturation = 255;
  2020. flip = 2;
  2021. } else if (flip == 2) {
  2022. color = 160;
  2023. saturation = 255;
  2024. bgcolor = 0;
  2025. bgsaturation = 0;
  2026. flip = 3;
  2027. } else if (flip == 3) {
  2028. color = 0;
  2029. saturation = 0;
  2030. bgcolor = 160;
  2031. bgsaturation = 255;
  2032. flip = 1;
  2033. }
  2034. }
  2035. for (int i = 0; i < NUM_LEDS; i++) {
  2036. leds[i] = CHSV(bgcolor, bgsaturation, 125);
  2037. }
  2038. resetF = 1;
  2039. currentpixel = NUM_LEDS - 1;
  2040.  
  2041. }
  2042. if (zFlag == 1 && justonce == 1) {
  2043. modA = random(0, 100);
  2044. if (modA < 55) {
  2045. currentpixel = currentpixel - 1;
  2046. }
  2047. else {
  2048. currentpixel = currentpixel + 1;
  2049. }
  2050. justonce = 0;
  2051. }
  2052. else if (zFlag == 0) {
  2053. justonce = 1;
  2054. }
  2055.  
  2056. if (currentpixel > NUM_LEDS - 1) {
  2057. currentpixel = NUM_LEDS - 1;
  2058. }
  2059.  
  2060. if (currentpixel < 1) {
  2061. resetF = 0;
  2062. }
  2063.  
  2064.  
  2065. for (int i = 0; i < NUM_LEDS; i++) {
  2066. if ((currentpixel - 1) < NUM_LEDS && (currentpixel - 1) >= 0) {
  2067. leds[currentpixel - 1] = CHSV(bgcolor, bgsaturation, 125);
  2068. }
  2069. if (currentpixel < NUM_LEDS && currentpixel >= 0) {
  2070. leds[currentpixel] = CHSV(color, saturation, 255);
  2071. }
  2072.  
  2073. }
  2074. }
  2075.  
  2076. void patriotic1() {
  2077. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement