Animations.ino 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. void animation_rainbow() {
  2. fill_rainbow(leds, NUM_LEDS, animation_i, animation_var_1);
  3. FastLED.show();
  4. animation_i++;
  5. animation_i %= 256;
  6. //Serial.println(animation_i);
  7. //Serial.println("Animation 1 step");
  8. }
  9. void animation_running() {
  10. //Serial.println("Animation 2 step");
  11. leds[animation_i] = CRGB(100, 255, 200);
  12. FastLED.show();
  13. animation_i++;
  14. if (animation_i >= NUMBER_OF_LEDS) {
  15. animation_i = 0;
  16. clear_strip();
  17. }
  18. }
  19. void animation_chasing() {
  20. //Serial.println("Animation 2 step");
  21. clear_strip();
  22. leds[animation_i*3] = CRGB(100, 255, 200);
  23. leds[(animation_i*3 + 10*3) % (NUMBER_OF_LEDS)] = CRGB(100, 255, 200);
  24. leds[(animation_i*3 + 20*3) % (NUMBER_OF_LEDS)] = CRGB(100, 255, 200);
  25. leds[((NUMBER_OF_LEDS) - animation_i*3) - 1*3] = CRGB(0, 255, 255);
  26. leds[animation_i*3+1] = CRGB(100, 255, 200);
  27. leds[(animation_i*3+1 + 10*3) % (NUMBER_OF_LEDS)] = CRGB(100, 255, 200);
  28. leds[(animation_i*3+1 + 20*3) % (NUMBER_OF_LEDS)] = CRGB(100, 255, 200);
  29. leds[((NUMBER_OF_LEDS) - animation_i*3+1) - 1*3] = CRGB(0, 255, 255);
  30. leds[animation_i*3+2] = CRGB(100, 255, 200);
  31. leds[(animation_i*3+2 + 10*3) % (NUMBER_OF_LEDS)] = CRGB(100, 255, 200);
  32. leds[(animation_i*3+2 + 20*3) % (NUMBER_OF_LEDS)] = CRGB(100, 255, 200);
  33. leds[((NUMBER_OF_LEDS) - animation_i*3+2) - 1*3] = CRGB(0, 255, 255);
  34. // leds[(50 - animation_i - 10)] = CRGB(0, 255, 255);
  35. // leds[(50 - animation_i)] = CRGB(0, 255, 255);
  36. FastLED.show();
  37. animation_i++;
  38. animation_i %= NUMBER_OF_LEDS/3;
  39. }
  40. void animation_off() {
  41. clear_strip();
  42. animation_step_time = 10000;
  43. }
  44. void animation_random1() {
  45. int difference = NUM_LEDS / animation_var_1;
  46. for (int i = 0; i < animation_var_1; i++) {
  47. int howManyCycles = animation_table_1[i][7];
  48. int currentStep = animation_table_1[i][6];
  49. uint8_t startRed = animation_table_1[i][0];
  50. uint8_t startGreen = animation_table_1[i][1];
  51. uint8_t startBlue = animation_table_1[i][2];
  52. uint8_t goalRed = animation_table_1[i][3];
  53. uint8_t goalGreen = animation_table_1[i][4];
  54. uint8_t goalBlue = animation_table_1[i][5];
  55. uint8_t r = (goalRed - startRed) * currentStep / howManyCycles + startRed;
  56. uint8_t g = (goalGreen - startGreen) * currentStep / howManyCycles + startGreen;
  57. uint8_t b = (goalBlue - startBlue) * currentStep / howManyCycles + startBlue;
  58. // for (int led = 0; led < 10; led++) {
  59. // leds[led + i * 10] = CRGB(r, b, g);
  60. // }
  61. leds[i * difference] = CRGB(r, b, g);
  62. animation_table_1[i][6] += 1;
  63. if (currentStep >= howManyCycles) {
  64. // uint8_t newR = (uint8_t) random(0, 255);
  65. // uint8_t newG = (uint8_t) random(0, 255);
  66. // uint8_t newB = (uint8_t) random(0, 255);
  67. uint8_t newH = (uint8_t) random(0, 255);
  68. uint8_t newS = (uint8_t) random(200, 255);
  69. CRGB newColor = CRGB(0, 0, 0);
  70. newColor.setHSV(newH, newS, 255);
  71. animation_table_1[i][3] = newColor.r;
  72. animation_table_1[i][4] = newColor.g;
  73. animation_table_1[i][5] = newColor.b;
  74. uint8_t steps = (uint8_t) random(50, 255);
  75. animation_table_1[i][0] = r;
  76. animation_table_1[i][1] = g;
  77. animation_table_1[i][2] = b;
  78. animation_table_1[i][7] = steps;
  79. animation_table_1[i][6] = 0;
  80. }
  81. }
  82. for (int i = 0; i < animation_var_1; i++) {
  83. uint8_t startRed = leds[i * difference].r;
  84. uint8_t startGreen = leds[i * difference].g;
  85. uint8_t startBlue = leds[i * difference].b;
  86. uint8_t goalRed = leds[((i + 1) * difference) % NUM_LEDS].r;
  87. uint8_t goalGreen = leds[((i + 1) * difference) % NUM_LEDS].g;
  88. uint8_t goalBlue = leds[((i + 1) * difference) % NUM_LEDS].b;
  89. for (int currentStep = 1; currentStep < difference; currentStep++) {
  90. uint8_t r = (goalRed - startRed) * currentStep / difference + startRed;
  91. uint8_t g = (goalGreen - startGreen) * currentStep / difference + startGreen;
  92. uint8_t b = (goalBlue - startBlue) * currentStep / difference + startBlue;
  93. leds[currentStep + i*difference] = CRGB(r, g, b);
  94. }
  95. }
  96. FastLED.show();
  97. }
  98. void animation_rgb_light() {
  99. FastLED.clear();
  100. for (int i = 0; i < NUM_LEDS/6; i++) {
  101. leds[(i + animation_i) % NUM_LEDS] = CRGB(255, 0, 0);
  102. leds[(i + animation_i + NUM_LEDS/3) % NUM_LEDS] = CRGB(0, 255, 0);
  103. leds[(i + animation_i + (NUM_LEDS/3)*2) % NUM_LEDS] = CRGB(0, 0, 255);
  104. }
  105. // for (int i = 1; i < NUM_LEDS/6; i++) { // Made an animation that already exists, but more complicated (animation_rainbow)
  106. // uint8_t r = (0 - 255) * i / 25 + 255;
  107. // uint8_t g = (255) * i / 25;
  108. // uint8_t b = 0;
  109. // leds[(i + animation_i + 25) % NUM_LEDS] = CRGB(r, g, b);
  110. // r = 0;
  111. // g = (0 - 255) * i / 25 + 255;
  112. // b = (255) * i / 25;
  113. // leds[(i + animation_i + 25 + 50) % NUM_LEDS] = CRGB(r, g, b);
  114. // r = (255 - 0) * i / 25 + 0;
  115. // g = 0;
  116. // b = (0 - 255) * i / 25 + 255;
  117. // leds[(i + animation_i + 25 + 100) % NUM_LEDS] = CRGB(r, g, b);
  118. // }
  119. FastLED.show();
  120. animation_i++;
  121. animation_i %= NUM_LEDS;
  122. }