kartonman

Daily Cycle For Loop Indexing

Sep 13th, 2021 (edited)
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. /*his sketch is still in beta. The timing of he color changes must be set as well as the length of the daily cycle.*/
  2. #include <FastLED.h>
  3.  
  4. #define dataPin 5
  5. #define Color_Order GRB
  6. #define CHIPSET WS2812B
  7. #define NUM_LEDS 15
  8. #define BRIGHTNESS 200
  9.  
  10. CRGB leds[NUM_LEDS];
  11.  
  12. DEFINE_GRADIENT_PALETTE(sunrise_gp) {
  13. 0, 0, 0, 0,
  14. 18, 98, 0, 0,
  15. 56, 161, 83, 0,
  16. 115, 212, 202, 0,
  17. 179, 255, 253, 213,
  18. 255, 255, 255, 255
  19. };
  20.  
  21. CRGBPalette256 sunPal = sunrise_gp;
  22. uint8_t paletteIndex = 0;
  23. bool countUp = true;
  24.  
  25. void setup() {
  26. FastLED.addLeds<CHIPSET, dataPin, Color_Order>(leds, NUM_LEDS);
  27. }
  28.  
  29. void loop() {
  30. EVERY_N_MILLISECONDS(100) {
  31. for (int i = 0; i < NUM_LEDS; i++) {
  32. leds[i] = ColorFromPalette(sunPal, paletteIndex);
  33. }
  34.  
  35. FastLED.show();
  36.  
  37. if (countUp) {
  38. paletteIndex += 1;
  39. if (paletteIndex == 255) {
  40. countUp = false;
  41. }
  42. } else {
  43. paletteIndex -= 1;
  44. if (paletteIndex == 0) {
  45. countUp = true;
  46. }
  47. }
  48. }
  49. }
Add Comment
Please, Sign In to add comment