Advertisement
BurningWreck

FastLED - multiple animations

Sep 5th, 2023 (edited)
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.90 KB | None | 0 0
  1. // ========== Animations ==========
  2.  
  3. // First animation
  4. const long ledarray0[] PROGMEM = {
  5. 0x00000000, 0x00000000, 0x00000000, 0x00000080, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  6. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  7. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  8. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  9. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  10. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  11. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  12. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  13. };
  14.  
  15. const long ledarray1[] PROGMEM = {
  16. 0x00000000, 0x00000000, 0x00000000, 0x00000080, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  17. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000080, 0x00000000, 0x00000000, 0x00000000,
  18. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  19. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  20. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  21. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  22. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  23. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  24. };
  25.  
  26. const long ledarray2[] PROGMEM = {
  27. 0x00000000, 0x00000000, 0x00000000, 0x00000080, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  28. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000080, 0x00000000, 0x00000000, 0x00000000,
  29. 0x00000000, 0x00000000, 0x00000000, 0x00000080, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  30. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  31. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  32. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  33. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  34. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  35. };
  36.  
  37. const long ledarray3[] PROGMEM = {
  38. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  39. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000080, 0x00000000, 0x00000000, 0x00000000,
  40. 0x00000000, 0x00000000, 0x00000000, 0x00000080, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  41. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000080, 0x00000000, 0x00000000, 0x00000000,
  42. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  43. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  44. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  45. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  46. };
  47.  
  48. const long ledarray4[] PROGMEM = {
  49. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  50. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  51. 0x00000000, 0x00000000, 0x00000000, 0x00000080, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  52. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000080, 0x00000000, 0x00000000, 0x00000000,
  53. 0x00000000, 0x00000000, 0x00000000, 0x00808000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  54. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  55. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  56. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  57. };
  58.  
  59. const long ledarray5[] PROGMEM = {
  60. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  61. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  62. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  63. 0x00000000, 0x00000000, 0x00000000, 0x00228000, 0x00000000, 0x00228000, 0x00000000, 0x00000000,
  64. 0x00000000, 0x00000000, 0x00000000, 0x00808000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  65. 0x00000000, 0x00000000, 0x00000000, 0x00228000, 0x00000000, 0x00228000, 0x00000000, 0x00000000,
  66. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  67. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  68. };
  69.  
  70. const long ledarray6[] PROGMEM = {
  71. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  72. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  73. 0x00000000, 0x00228000, 0x00000000, 0x00000000, 0x00000000, 0x00228000, 0x00000000, 0x00000000,
  74. 0x00000000, 0x00000000, 0x00000000, 0x00228000, 0x00000000, 0x00228000, 0x00000000, 0x00000000,
  75. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  76. 0x00000000, 0x00000000, 0x00000000, 0x00228000, 0x00000000, 0x00228000, 0x00000000, 0x00000000,
  77. 0x00000000, 0x00228000, 0x00000000, 0x00000000, 0x00000000, 0x00228000, 0x00000000, 0x00000000,
  78. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  79. };
  80.  
  81. const long ledarray7[] PROGMEM = {
  82. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  83. 0x00000000, 0x00228000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00228000,
  84. 0x00000000, 0x00228000, 0x00000000, 0x00000000, 0x00000000, 0x00228000, 0x00000000, 0x00000000,
  85. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  86. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  87. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  88. 0x00000000, 0x00228000, 0x00000000, 0x00000000, 0x00000000, 0x00228000, 0x00000000, 0x00000000,
  89. 0x00000000, 0x00228000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00228000,
  90. };
  91.  
  92. const long ledarray8[] PROGMEM = {
  93. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00228000,
  94. 0x00000000, 0x00228000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00228000,
  95. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  96. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  97. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  98. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  99. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  100. 0x00000000, 0x00228000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00228000,
  101. };
  102.  
  103. const long ledarray9[] PROGMEM = {
  104. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00228000,
  105. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  106. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  107. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  108. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  109. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  110. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  111. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  112. };
  113.  
  114. const long ledarray10[] PROGMEM = {
  115. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  116. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  117. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  118. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  119. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  120. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  121. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  122. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  123. };
  124.  
  125. // Second animation
  126.  
  127.  
  128.  
  129. // Third animation
  130.  
  131. // =======================
  132.  
  133. // FastLED
  134. #include "FastLED.h"
  135. #define LED_TYPE NEOPIXEL
  136. #define DATA_PIN A3
  137. #define MASTER_BRIGHTNESS 255
  138. #define MATRIX_HEIGHT 8
  139. #define MATRIX_WIDTH 8
  140. #define NUM_LEDS MATRIX_HEIGHT*MATRIX_WIDTH
  141. CRGB leds[NUM_LEDS];
  142.  
  143. const int __NUM_LEDS = 64; // per frame
  144. const unsigned long __DELAY_MS = 80; // controls speed of animations
  145.  
  146. uint8_t hue = 96; // Hue color (0-255) 255 - red, 96 - green,
  147. // const byte off = 0; // brightness values
  148. const byte low = 85;
  149. const byte med = 155;
  150. const byte high = 255;
  151.  
  152. #include <EdgeDebounce.h>
  153.  
  154. const int button1_pin = 10;
  155. const int button2_pin = 12;
  156. const int button3_pin = A0;
  157.  
  158. EdgeDebounce button1(button1_pin, PULLUP);
  159. EdgeDebounce button2(button2_pin, PULLUP);
  160. EdgeDebounce button3(button3_pin, PULLUP);
  161.  
  162. int launchMode = 0;
  163.  
  164. void setup() {
  165.  
  166. FastLED.addLeds<LED_TYPE, DATA_PIN>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
  167. FastLED.setBrightness(MASTER_BRIGHTNESS);
  168.  
  169. button1.begin();
  170. button2.begin();
  171. button3.begin();
  172.  
  173. }
  174.  
  175. void loop() {
  176.  
  177. checkButtons();
  178. ButtonLaunch();
  179.  
  180. }
  181.  
  182. void ButtonLaunch() {
  183. switch (launchMode) {
  184. case 0: allOff(); break;
  185. case 1: launchSmall(); break;
  186. case 2: launchMedium(); break;
  187. case 3: launchLarge(); break;
  188. }
  189. }
  190.  
  191. void launchSmall() {
  192.  
  193. FastLED.clear();
  194. for(int i = 0; i < __NUM_LEDS; i++)
  195. {
  196. leds[i] = pgm_read_dword(&(ledarray0[i]));
  197. }
  198. FastLED.show();
  199. delay(__DELAY_MS);
  200.  
  201. FastLED.clear();
  202. for(int i = 0; i < __NUM_LEDS; i++)
  203. {
  204. leds[i] = pgm_read_dword(&(ledarray1[i]));
  205. }
  206. FastLED.show();
  207. delay(__DELAY_MS);
  208.  
  209. FastLED.clear();
  210. for(int i = 0; i < __NUM_LEDS; i++)
  211. {
  212. leds[i] = pgm_read_dword(&(ledarray2[i]));
  213. }
  214. FastLED.show();
  215. delay(__DELAY_MS);
  216.  
  217. FastLED.clear();
  218. for(int i = 0; i < __NUM_LEDS; i++)
  219. {
  220. leds[i] = pgm_read_dword(&(ledarray3[i]));
  221. }
  222. FastLED.show();
  223. delay(__DELAY_MS);
  224.  
  225. FastLED.clear();
  226. for(int i = 0; i < __NUM_LEDS; i++)
  227. {
  228. leds[i] = pgm_read_dword(&(ledarray4[i]));
  229. }
  230. FastLED.show();
  231. delay(__DELAY_MS);
  232.  
  233. FastLED.clear();
  234. for(int i = 0; i < __NUM_LEDS; i++)
  235. {
  236. leds[i] = pgm_read_dword(&(ledarray5[i]));
  237. }
  238. FastLED.show();
  239. delay(__DELAY_MS);
  240.  
  241. FastLED.clear();
  242. for(int i = 0; i < __NUM_LEDS; i++)
  243. {
  244. leds[i] = pgm_read_dword(&(ledarray6[i]));
  245. }
  246. FastLED.show();
  247. delay(__DELAY_MS);
  248.  
  249. FastLED.clear();
  250. for(int i = 0; i < __NUM_LEDS; i++)
  251. {
  252. leds[i] = pgm_read_dword(&(ledarray7[i]));
  253. }
  254. FastLED.show();
  255. delay(__DELAY_MS);
  256.  
  257. FastLED.clear();
  258. for(int i = 0; i < __NUM_LEDS; i++)
  259. {
  260. leds[i] = pgm_read_dword(&(ledarray8[i]));
  261. }
  262. FastLED.show();
  263. delay(__DELAY_MS);
  264.  
  265. FastLED.clear();
  266. for(int i = 0; i < __NUM_LEDS; i++)
  267. {
  268. leds[i] = pgm_read_dword(&(ledarray9[i]));
  269. }
  270. FastLED.show();
  271. delay(__DELAY_MS);
  272.  
  273. FastLED.clear();
  274. for(int i = 0; i < __NUM_LEDS; i++)
  275. {
  276. leds[i] = pgm_read_dword(&(ledarray10[i]));
  277. }
  278. FastLED.show();
  279. delay(__DELAY_MS);
  280.  
  281. }
  282.  
  283. void launchMedium() {
  284. }
  285.  
  286. void launchLarge() {
  287. }
  288.  
  289. // upgrade this function to take hue as well as brightness
  290.  
  291.  
  292. void allOff(){
  293. for (int i = 0; i < NUM_LEDS; ++i) {
  294. leds[i] = CRGB::Black;
  295. FastLED.show();
  296. }
  297. }
  298.  
  299. void checkButtons() {
  300. // Set buttonMode based on which button is pressed. HIGH is open, LOW is pressed.
  301. if (button1.rose()) {
  302. launchMode = 1;
  303. } else if (button2.rose()) {
  304. launchMode = 2;
  305. } else if (button3.rose()) {
  306. launchMode = 3;
  307. } else {
  308. launchMode = 0;
  309. }
  310. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement