kartonman

sunrise to sunset from timing sketch

Sep 8th, 2021
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. //sunrise to sunset from timing sketch
  2.  
  3. #define FASTLED_INTERNAL
  4. #include <FastLED.h>
  5. #include <Wire.h>
  6.  
  7.  
  8. #define NUM_LEDS 6
  9. #define DATA_PIN 6
  10. #define am1 7
  11. int am1state = 0;
  12. uint16_t currentPixel = 0;
  13. uint16_t led = 0;
  14. byte maxBrightness = 150;
  15.  
  16. //----------PALETTES-----------
  17.  
  18. DEFINE_GRADIENT_PALETTE (am_gp) { // 0000 TO 1200
  19. 0, 0, 0, 0, //black
  20. 18, 0, 0, 0, //dark red
  21. 56, 161, 83, 0, //orange
  22. 115, 212, 202, 0, //dark yellow
  23. 179, 255, 253, 213, //bright yellow
  24. 255, 255, 255, 255, //white
  25. };
  26.  
  27. DEFINE_GRADIENT_PALETTE (pm_gp) { // 1200 To 0000
  28. 0, 255, 255, 255, //white
  29. 18, 255, 253, 213, //bright yellow
  30. 56, 212, 202, 0, //dark yellow
  31. 115, 161, 83, 0, //orange
  32. 179, 98, 0, 0, //dark red
  33. 255, 0, 0, 0 , //black}
  34. };
  35.  
  36. CRGBPalette16 myPal1 = am_gp;
  37. CRGBPalette16 myPal2 = pm_gp;
  38.  
  39.  
  40. struct CRGB leds[NUM_LEDS];
  41. static uint8_t paletteIndex = 0;
  42.  
  43. //------------SETUP-------------
  44.  
  45. void setup() {
  46. FastLED.addLeds<WS2811, DATA_PIN, RGB>(leds, NUM_LEDS);
  47. pinMode(am1, INPUT);
  48. }
  49.  
  50. //------------LOOP-------------
  51.  
  52. void loop() {
  53.  
  54. amCycle();
  55. FastLED.show();
  56. pmCycle();
  57. FastLED.show();
  58. }
  59.  
  60. //Functions------------------------------
  61.  
  62. void amCycle()
  63. {
  64. CRGB colour = ColorFromPalette(myPal1, paletteIndex, maxBrightness, LINEARBLEND);
  65. fill_solid(leds, NUM_LEDS, colour);
  66.  
  67. EVERY_N_MILLISECONDS(1000) {
  68. if (paletteIndex < 255) {
  69. paletteIndex++;
  70. }
  71. if (paletteIndex == 255) {
  72. paletteIndex = 0;
  73. }
  74. }
  75. }
  76.  
  77. //*****************************************
  78. void pmCycle()
  79. {
  80. CRGB colour2 = ColorFromPalette(myPal2, paletteIndex, maxBrightness, LINEARBLEND);
  81. fill_solid(leds, NUM_LEDS, colour2);
  82. EVERY_N_MILLISECONDS(1000) {
  83. if (paletteIndex < 255) {
  84. paletteIndex++;
  85. }
  86. if (paletteIndex >= 255) {
  87. paletteIndex = 0;
  88. }
  89. }
  90. }
  91.  
Advertisement
Add Comment
Please, Sign In to add comment