Animations.ino 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. //0: animation_number
  2. //1: NUM_LEDS
  3. //2: led_offset
  4. //3: speed
  5. //4: table
  6. //5: var_1
  7. //6: i
  8. //7: lastAnimationMillis
  9. int getVariables(int stripDiv) {
  10. return current_animation_table[stripDiv][1], current_animation_table[stripDiv][2], current_animation_table[stripDiv][6], current_animation_table[stripDiv][5];
  11. }
  12. void saveAnimI(int animI, int stripDiv) {
  13. current_animation_table[stripDiv][6] = animI;
  14. }
  15. void animation_rainbow(int stripDiv) {
  16. int numLeds, offset, animI, animVar1 = getVariables(stripDiv);
  17. int h = animI;
  18. for (int i = 0; i < numLeds; i++) {
  19. h = (h + animVar1) % 256;
  20. leds[i + offset] = CHSV(h, 255, 255);
  21. }
  22. //fill_rainbow(leds, NUM_LEDS, animation_i, animation_var_1);
  23. FastLED.show();
  24. animI++;
  25. animI %= 256;
  26. saveAnimI(animI, stripDiv);
  27. //Serial.println(animation_i);
  28. //Serial.println("Animation 1 step");
  29. }
  30. void animation_running(int stripDiv) {
  31. //Serial.println("Animation 2 step");
  32. int numLeds, offset, animI, animVar1 = getVariables(stripDiv);
  33. leds[animI] = CRGB(100, 255, 200);
  34. FastLED.show();
  35. animI++;
  36. if (animation_i >= numLeds) {
  37. animI = 0;
  38. clear_strip(stripDiv);
  39. }
  40. saveAnimI(animI, stripDiv);
  41. }
  42. void animation_chasing(int stripDiv) {
  43. //Serial.println("Animation 2 step");
  44. int numLeds, offset, animI, animVar1 = getVariables(stripDiv);
  45. clear_strip(stripDiv);
  46. leds[animI] = CRGB(100, 255, 200);
  47. leds[((animI + 10) % numLeds) + offset] = CRGB(100, 255, 200);
  48. leds[((animI + 20) % numLeds) + offset] = CRGB(100, 255, 200);
  49. leds[((numLeds) - animI) - 1 + offset] = CRGB(0, 255, 255);
  50. // leds[animation_i * 3 + 1] = CRGB(100, 255, 200);
  51. // leds[(animation_i * 3 + 1 + 10 * 3) % (NUMBER_OF_LEDS)] = CRGB(100, 255, 200);
  52. // leds[(animation_i * 3 + 1 + 20 * 3) % (NUMBER_OF_LEDS)] = CRGB(100, 255, 200);
  53. // leds[((NUMBER_OF_LEDS) - animation_i * 3 + 1) - 1 * 3] = CRGB(0, 255, 255);
  54. //
  55. // leds[animation_i * 3 + 2] = CRGB(100, 255, 200);
  56. // leds[(animation_i * 3 + 2 + 10 * 3) % (NUMBER_OF_LEDS)] = CRGB(100, 255, 200);
  57. // leds[(animation_i * 3 + 2 + 20 * 3) % (NUMBER_OF_LEDS)] = CRGB(100, 255, 200);
  58. // leds[((NUMBER_OF_LEDS) - animation_i * 3 + 2) - 1 * 3] = CRGB(0, 255, 255);
  59. // leds[(50 - animation_i - 10)] = CRGB(0, 255, 255);
  60. // leds[(50 - animation_i)] = CRGB(0, 255, 255);
  61. FastLED.show();
  62. animI++;
  63. animI %= numLeds;
  64. saveAnimI(animI, stripDiv);
  65. }
  66. void animation_off(int stripDiv) {
  67. clear_strip(stripDiv);
  68. current_animation_table[stripDiv][3] = 10000;
  69. }
  70. void animation_random1(int stripDiv) {
  71. int numLeds, offset, animI, animVar1 = getVariables(stripDiv);
  72. int difference = numLeds / animVar1;
  73. for (int i = 0; i < animVar1; i++) {
  74. int howManyCycles = animation_table_1[stripDiv][i][7];
  75. int currentStep = animation_table_1[stripDiv][i][6];
  76. uint8_t startRed = animation_table_1[stripDiv][i][0];
  77. uint8_t startGreen = animation_table_1[stripDiv][i][1];
  78. uint8_t startBlue = animation_table_1[stripDiv][i][2];
  79. uint8_t goalRed = animation_table_1[stripDiv][i][3];
  80. uint8_t goalGreen = animation_table_1[stripDiv][i][4];
  81. uint8_t goalBlue = animation_table_1[stripDiv][i][5];
  82. uint8_t r = (goalRed - startRed) * currentStep / howManyCycles + startRed;
  83. uint8_t g = (goalGreen - startGreen) * currentStep / howManyCycles + startGreen;
  84. uint8_t b = (goalBlue - startBlue) * currentStep / howManyCycles + startBlue;
  85. // for (int led = 0; led < 10; led++) {
  86. // leds[led + i * 10] = CRGB(r, b, g);
  87. // }
  88. leds[i * difference + offset] = CRGB(r, b, g);
  89. animation_table_1[stripDiv][i][6] += 1;
  90. if (currentStep >= howManyCycles) {
  91. // uint8_t newR = (uint8_t) random(0, 255);
  92. // uint8_t newG = (uint8_t) random(0, 255);
  93. // uint8_t newB = (uint8_t) random(0, 255);
  94. uint8_t newH = (uint8_t) random(0, 255);
  95. uint8_t newS = (uint8_t) random(200, 255);
  96. CRGB newColor = CRGB(0, 0, 0);
  97. newColor.setHSV(newH, newS, 255);
  98. animation_table_1[stripDiv][i][3] = newColor.r;
  99. animation_table_1[stripDiv][i][4] = newColor.g;
  100. animation_table_1[stripDiv][i][5] = newColor.b;
  101. uint8_t steps = (uint8_t) random(50, 255);
  102. animation_table_1[stripDiv][i][0] = r;
  103. animation_table_1[stripDiv][i][1] = g;
  104. animation_table_1[stripDiv][i][2] = b;
  105. animation_table_1[stripDiv][i][7] = steps;
  106. animation_table_1[stripDiv][i][6] = 0;
  107. }
  108. }
  109. for (int i = 0; i < animVar1; i++) {
  110. uint8_t startRed = leds[i * difference + offset].r;
  111. uint8_t startGreen = leds[i * difference + offset].g;
  112. uint8_t startBlue = leds[i * difference + offset].b;
  113. uint8_t goalRed = leds[((i + 1) * difference) % numLeds + offset].r;
  114. uint8_t goalGreen = leds[((i + 1) * difference) % numLeds + offset].g;
  115. uint8_t goalBlue = leds[((i + 1) * difference) % numLeds + offset].b;
  116. for (int currentStep = 1; currentStep < difference; currentStep++) {
  117. uint8_t r = (goalRed - startRed) * currentStep / difference + startRed;
  118. uint8_t g = (goalGreen - startGreen) * currentStep / difference + startGreen;
  119. uint8_t b = (goalBlue - startBlue) * currentStep / difference + startBlue;
  120. leds[currentStep + i * difference + offset] = CRGB(r, g, b);
  121. }
  122. }
  123. FastLED.show();
  124. }
  125. void animation_rgb_light(int stripDiv) {
  126. int numLeds, offset, animI, animVar1 = getVariables(stripDiv);
  127. clear_strip(stripDiv);
  128. for (int i = offset; i < (numLeds + offset) / 6; i++) {
  129. leds[(i + animation_i) % numLeds] = CRGB(255, 0, 0);
  130. leds[(i + animation_i + numLeds / 3) % numLeds] = CRGB(0, 255, 0);
  131. leds[(i + animation_i + (numLeds / 3) * 2) % numLeds] = CRGB(0, 0, 255);
  132. }
  133. // for (int i = 1; i < NUM_LEDS/6; i++) { // Made an animation that already exists, but more complicated (animation_rainbow)
  134. // uint8_t r = (0 - 255) * i / 25 + 255;
  135. // uint8_t g = (255) * i / 25;
  136. // uint8_t b = 0;
  137. // leds[(i + animation_i + 25) % NUM_LEDS] = CRGB(r, g, b);
  138. // r = 0;
  139. // g = (0 - 255) * i / 25 + 255;
  140. // b = (255) * i / 25;
  141. // leds[(i + animation_i + 25 + 50) % NUM_LEDS] = CRGB(r, g, b);
  142. // r = (255 - 0) * i / 25 + 0;
  143. // g = 0;
  144. // b = (0 - 255) * i / 25 + 255;
  145. // leds[(i + animation_i + 25 + 100) % NUM_LEDS] = CRGB(r, g, b);
  146. // }
  147. FastLED.show();
  148. animI++;
  149. animI %= numLeds;
  150. saveAnimI(animI, stripDiv);
  151. }
  152. void animation_random2(int stripDiv) {
  153. int numLeds, offset, animI, animVar1 = getVariables(stripDiv);
  154. if (random(0, animVar1) == 0) {
  155. //Serial.println("Stage 1");
  156. for (int i = 0; i < 10; i++) {
  157. //Serial.println("Stage 2");
  158. //Serial.println(animation_table_1[i][1]);
  159. if (animation_table_1[stripDiv][i][1] == 0) {
  160. //Serial.println("Stage 3");
  161. int randomDot = random(0, numLeds);
  162. //Serial.println(randomDot);
  163. if (!leds[randomDot]) {
  164. //Serial.println("Stage 4");
  165. animation_table_1[stripDiv][i][0] = random(0, 255);
  166. animation_table_1[stripDiv][i][1] = 255;
  167. animation_table_1[stripDiv][i][2] = randomDot;
  168. animation_table_1[stripDiv][i][3] = 1;
  169. //Serial.println(animation_table_1[i][0]);
  170. leds[randomDot + offset] = CHSV(animation_table_1[stripDiv][i][0], 255, 126);
  171. break;
  172. }
  173. }
  174. }
  175. }
  176. for (int i = 0; i < 10; i++) {
  177. if (animation_table_1[stripDiv][i][3] == 1) {
  178. leds[animation_table_1[stripDiv][i][2] + offset] = CHSV(animation_table_1[stripDiv][i][0], 255, 126);
  179. animation_table_1[stripDiv][i][3] = 2;
  180. } else if (animation_table_1[stripDiv][i][3] == 2) {
  181. leds[animation_table_1[stripDiv][i][2] + offset] = CHSV(animation_table_1[stripDiv][i][0], 255, 255);
  182. animation_table_1[stripDiv][i][3] = 0;
  183. } else {
  184. animation_table_1[stripDiv][i][1] = max(animation_table_1[stripDiv][i][1] - 10, 0);
  185. leds[animation_table_1[stripDiv][i][2] + offset] = CHSV(animation_table_1[stripDiv][i][0], 255, animation_table_1[stripDiv][i][1]);
  186. }
  187. }
  188. // if (animation_i <= animation_var_1) {
  189. // int randomDot = random(0, NUMBER_OF_LEDS);
  190. // if (!leds[randomDot]) {
  191. // leds[randomDot] = CHSV(random(0, 255), 255, 255);
  192. // animation_i += 1;
  193. // }
  194. // } else {
  195. // for (int i = 0; i < NUM_LEDS; i++) {
  196. // if (leds[i]) {
  197. // if (random(1, animation_var_1) == 1) {
  198. // leds[i] = CRGB(0, 0, 0);
  199. // animation_i -= 1;
  200. // }
  201. // }
  202. // }
  203. // }
  204. FastLED.show();
  205. }