Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Arduino.h>
- #include <FastLED.h>
- #include <TFT_eSPI.h>
- #include <SPI.h>
- // Declare all variables that are needed to get the lights working
- #define NUM_LEDS_PANEL 33
- #define NUM_PANELS 7
- #define DATA_PIN 15
- // variable parameters
- uint8_t brightness = 200;
- uint8_t hue = 0;
- uint8_t hueStart = 0;
- uint8_t value = 255;
- uint8_t saturation = 255;
- // Now add some parameters for the rainbow effect
- // First the speed with which the colors change
- const unsigned long rainbowInterval = 100;
- // Second the previous time object so the rainbow function knows when it needs to add to the hue
- unsigned long previousTimeRainbow;
- // Initialise the array that holds the rgb information on each LED
- CRGB leds[NUM_LEDS_PANEL * NUM_PANELS];
- TFT_eSPI tft = TFT_eSPI();
- // Define functions in forward declaration
- void rainbow_move() {
- // Let's start of with a rainbow that moves with time
- // First we set the rainbow in it's starting state and define the starting state
- // For this we need to fill every panel with a color
- if(millis() - previousTimeRainbow >= rainbowInterval) {
- // set all panels to a different color equally spaced on the color spectrum
- for(int idPanel = 0; idPanel < NUM_PANELS; idPanel++){
- // first we need to set the hue back to the first hue so the panels change color smoothly
- // but only if this is the first panel (this panel 'remembers' it's previous hue)
- if(idPanel == 0){
- // Set hue back to hue start
- hue = hueStart;
- }
- // set all LEDs in a panel to the same color
- for(int idLed = 0; idLed < NUM_LEDS_PANEL; idLed++){
- leds[idPanel * NUM_LEDS_PANEL + idLed] = CHSV(hue, saturation, value);
- }
- // Now change the hue so the next panel is next on the color spectrum
- hue = hue + 256/NUM_PANELS;
- }
- // 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
- hueStart++;
- previousTimeRainbow = millis();
- //Serial.println(hue);
- //Serial.println("Change hue!");
- tft.setCursor(0,24);
- tft.fillScreen(TFT_BLACK);
- tft.print("HUE ");
- tft.print(hue);
- tft.print(" Hue start ");
- tft.print(hueStart);
- }
- }
- void setup() {
- // put your setup code here, to run once:
- // initialise LEDs
- pinMode(DATA_PIN,OUTPUT);
- FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS_PANEL * NUM_PANELS);
- FastLED.setBrightness(brightness);
- // set the brightness
- //FastLED.setBrightness(brightness);
- // tft screen stuff
- tft.begin();
- tft.setRotation(1);
- tft.fillScreen(TFT_BLACK);
- tft.setTextColor(TFT_GREEN, TFT_BLACK);
- tft.setFreeFont(&Orbitron_Light_24);
- tft.setTextPadding(tft.width());
- }
- void loop() {
- // put your main code here, to run repeatedly:
- // if(millis()- previousTimeRainbow > rainbowInterval){
- // if(brightness < 100){
- // brightness++;
- // }
- // else{
- // brightness = 20;
- // }
- // }
- // Now run the rainbow function to change hue
- rainbow_move();
- // Finally send the command to the LEDs
- FastLED.show();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement