Animations.ino 9.8 KB

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