Advertisement
Guest User

Untitled

a guest
Jan 5th, 2024
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.08 KB | Source Code | 0 0
  1. #include <Arduino.h>
  2. #include <FastLED.h>
  3. #include <TFT_eSPI.h>
  4. #include <SPI.h>
  5.  
  6. // Declare all variables that are needed to get the lights working
  7. #define NUM_LEDS_PANEL 33
  8. #define NUM_PANELS 7
  9. #define DATA_PIN 15
  10.  
  11. // variable parameters
  12. uint8_t brightness = 200;
  13. uint8_t hue = 0;
  14. uint8_t hueStart = 0;
  15. uint8_t value = 255;
  16. uint8_t saturation = 255;
  17.  
  18. // Now add some parameters for the rainbow effect
  19. // First the speed with which the colors change
  20. const unsigned long rainbowInterval = 100;
  21. // Second the previous time object so the rainbow function knows when it needs to add to the hue
  22. unsigned long previousTimeRainbow;
  23. // Initialise the array that holds the rgb information on each LED
  24. CRGB leds[NUM_LEDS_PANEL * NUM_PANELS];
  25. TFT_eSPI tft = TFT_eSPI();
  26.  
  27. // Define functions in forward declaration
  28. void rainbow_move() {
  29.   // Let's start of with a rainbow that moves with time
  30.   // First we set the rainbow in it's starting state and define the starting state
  31.   // For this we need to fill every panel with a color
  32.   if(millis() - previousTimeRainbow >= rainbowInterval) {
  33.     // set all panels to a different color equally spaced on the color spectrum
  34.     for(int idPanel = 0; idPanel < NUM_PANELS; idPanel++){
  35.       // first we need to set the hue back to the first hue so the panels change color smoothly
  36.       // but only if this is the first panel (this panel 'remembers' it's previous hue)
  37.       if(idPanel == 0){
  38.       // Set hue back to hue start
  39.         hue = hueStart;
  40.       }
  41.       // set all LEDs in a panel to the same color
  42.       for(int idLed = 0; idLed < NUM_LEDS_PANEL; idLed++){
  43.         leds[idPanel * NUM_LEDS_PANEL + idLed] = CHSV(hue, saturation, value);
  44.       }
  45.       // Now change the hue so the next panel is next on the color spectrum
  46.       hue = hue + 256/NUM_PANELS;
  47.     }
  48.     // Now that all colors are set add 1 to the hue of the first panel so next time it will be shifted in color slightly
  49.     hueStart++;
  50.     previousTimeRainbow = millis();
  51.     //Serial.println(hue);
  52.     //Serial.println("Change hue!");
  53.     tft.setCursor(0,24);
  54.     tft.fillScreen(TFT_BLACK);
  55.     tft.print("HUE ");
  56.     tft.print(hue);
  57.     tft.print("  Hue start ");
  58.     tft.print(hueStart);
  59.   }
  60. }
  61.  
  62. void setup() {
  63.   // put your setup code here, to run once:
  64.   // initialise LEDs
  65.   pinMode(DATA_PIN,OUTPUT);
  66.   FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS_PANEL * NUM_PANELS);
  67.   FastLED.setBrightness(brightness);
  68.   // set the brightness
  69.   //FastLED.setBrightness(brightness);
  70.   // tft screen stuff
  71.   tft.begin();
  72.   tft.setRotation(1);
  73.   tft.fillScreen(TFT_BLACK);
  74.   tft.setTextColor(TFT_GREEN, TFT_BLACK);
  75.   tft.setFreeFont(&Orbitron_Light_24);
  76.   tft.setTextPadding(tft.width());
  77.  
  78. }
  79.  
  80. void loop() {
  81.   // put your main code here, to run repeatedly:
  82.   // if(millis()- previousTimeRainbow > rainbowInterval){
  83.   //   if(brightness < 100){
  84.   //     brightness++;
  85.   //   }
  86.   //   else{
  87.   //     brightness = 20;
  88.   //   }
  89.   // }
  90.   // Now run the rainbow function to change hue
  91.   rainbow_move();
  92.   // Finally send the command to the LEDs
  93.   FastLED.show();
  94. }
  95.  
  96.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement