Advertisement
kartonman

sunrise to sunset from timing sketch mod 1

Sep 8th, 2021
240
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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,
  20. 30, 100, 0, 0,
  21. 54, 161, 83, 60,
  22. 75, 212, 100, 80,
  23. 100, 255, 175, 150,
  24. 135, 255, 253, 200,
  25. 150, 255, 253, 213,
  26. 179, 255, 253, 255,
  27. 255, 255, 255, 255
  28. };
  29.  
  30. DEFINE_GRADIENT_PALETTE (pm_gp) { // 1200 To 0000
  31. 0, 255, 255, 255, //white
  32. 18, 255, 253, 213, //bright yellow
  33. 56, 212, 202, 0, //dark yellow
  34. 115, 161, 83, 0, //orange
  35. 179, 0, 0, 0, //dark red
  36. 255, 0, 0, 0 //black}
  37. };
  38.  
  39. CRGBPalette16 myPal1 = am_gp;
  40. CRGBPalette16 myPal2 = pm_gp;
  41.  
  42.  
  43. struct CRGB leds[NUM_LEDS];
  44. static uint8_t paletteIndex = 0;
  45.  
  46. //------------SETUP-------------
  47.  
  48. void setup() {
  49. FastLED.addLeds<WS2811, DATA_PIN, BRG>(leds, NUM_LEDS);
  50. pinMode(am1, INPUT);
  51. }
  52.  
  53. //------------LOOP-------------
  54.  
  55. void loop() {
  56.  
  57. pmCycle();
  58. FastLED.show();
  59. amCycle();
  60. FastLED.show();
  61. }
  62.  
  63. //Functions------------------------------
  64.  
  65. void amCycle()
  66. {
  67. CRGB colour = ColorFromPalette(myPal1, paletteIndex, maxBrightness, LINEARBLEND);
  68. fill_solid(leds, NUM_LEDS, colour);
  69.  
  70. EVERY_N_MILLISECONDS(1000) {
  71. while (paletteIndex <=256) {
  72. paletteIndex++;
  73. }
  74. }
  75. if (paletteIndex >=255){
  76. paletteIndex=0;}
  77. }
  78.  
  79.  
  80. //*****************************************
  81. void pmCycle()
  82. {
  83. CRGB colour2 = ColorFromPalette(myPal2, paletteIndex, maxBrightness, LINEARBLEND);
  84. fill_solid(leds, NUM_LEDS, colour2);
  85. EVERY_N_MILLISECONDS(1000) {
  86. while (paletteIndex <= 256) {
  87. paletteIndex++;
  88. }
  89. if (paletteIndex >=255){
  90. paletteIndex=0;}
  91. }
  92. }
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement