Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* this sketch has the modified pallets. Only two pallets.
- Daily Cycle sketch for RGB led type WS2811
- Meanwhile the street lights are gradually switched On and Off.*/
- #define FASTLED_INTERNAL
- #include <FastLED.h>
- #include <Wire.h>
- #define NUM_LEDS 3 // NUMBER OF PIXELS IN THE USED STRIP
- #define DATA_PIN 6
- uint16_t currentPixel = 0; // SET TO PIXEL NUMBER 0
- uint16_t led = 0;
- #define STREET_LED 9 // THE PIN THAT THE STREET LEDs ARE ATTACHED TO
- #define STREET_LED2 10 // THE PIN THAT THE STREET LEDs ARE ATTACHED TO
- #define toggle1 8 // to trigger external board
- #define toggle2 7 // to trigger external board
- int brightness_STREET = 0; // BRIGHTNESS OF THE STREET LEDs AT STARTUP
- int fadeAmount = 1; // KeeP THIS AMOUNT UNDER 5 FOR A NICE FADING OF THE STREET LEDs
- //-----------TIMING------------
- unsigned long currentMillis = 0;
- unsigned long previousMillis = 0;
- unsigned long speedOfEveningToMorning = 200; // DURATION IN STEPS OF nightcycle ROUTINE - 6steps/second (1 minute = 360 steps)
- unsigned long speedOfMorningToEvening = 200; // DURATION IN STEPS OF daycle ROUTINE - 6steps/second (1 minute = 360 steps)
- unsigned long timeBaseInterval = speedOfMorningToEvening + speedOfEveningToMorning; // TIMEBASE FOR THE nightcycle + daycycle
- unsigned long time_Now = 0;
- byte maxBrightness = 150; // VALUES FROM 0 - 255 -> THE HIGHER, THE MORE Amps NEEDED - FOR THE LED STRIPS
- static const float intervalMorningToEvening = speedOfMorningToEvening;
- static const float intervalEveningToMorning = speedOfEveningToMorning;
- //----------PALETTES-----------
- DEFINE_GRADIENT_PALETTE (Evening_To_Morning_gp) { // EVENIG TO MORNING PALETTE (nightcycle)
- 0, 0, 0, 0, //black
- 18, 0, 0, 0, //dark red
- 56, 161, 83, 0, //orange
- 115, 212, 202, 0, //dark yellow
- 179, 255, 253, 213, //bright yellow
- 255, 255, 255, 255, //white
- };
- DEFINE_GRADIENT_PALETTE (Morning_To_Evening_gp) { // MORNING TO NOON PALETTE (daycycle)
- 0, 255, 255, 255, //white
- 18, 255, 253, 213, //bright yellow
- 56, 212, 202, 0, //dark yellow
- 115, 161, 83, 0, //orange
- 179, 98, 0, 0, //dark red
- 255, 0, 0, 0 //black
- CRGBPalette16 myPal1 = Evening_To_Morning_gp; // CREATING PALETTE OBJECTS AS MANY AS THERE ARE PALETTES IN USE
- CRGBPalette16 myPal2 = Morning_To_Evening_gp;
- struct CRGB leds[NUM_LEDS]; // DEFINE OBJECT OF LEDS
- static uint8_t paletteIndex = 0; // CURRENT GRADIENT PALETTE COLOUR
- //------------------------------
- //------------SETUP-------------
- void setup() {
- Serial.begin(9600);
- FastLED.addLeds<WS2811, DATA_PIN, BRG>(leds, NUM_LEDS); // BRG SEQUENCE IN PLACE OF RGB FOR MY STRIP
- pinMode(STREET_LED, OUTPUT);
- pinMode(STREET_LED2, OUTPUT);
- pinMode(toggle1, OUTPUT);
- pinMode(toggle2, OUTPUT);
- }
- //-----------------------------
- //------------LOOP-------------
- void loop() {
- nightycle();
- dayCycle();
- FastLED.show();
- currentMillis = millis(); // capture the latest value of millis()
- // this is equivalent to noting the time from a clock
- // use the same time for all LED flashes to keep them synchronized
- if (millis() >= time_Now + timeBaseInterval)
- {
- time_Now += timeBaseInterval;
- streetLightFading();
- }
- }
- //------------------------------
- //-----DAY TO NIGHT CYCLES------
- void nightycle()
- {
- CRGB colour = ColorFromPalette(myPal1, paletteIndex, maxBrightness, LINEARBLEND); // OR EVENTUALLY A BUILT-IN PALETTE
- fill_solid(leds, NUM_LEDS, colour); // LIGHT THE WHOLE STRIP WITH THE COLOUR GRABBED FROM THE PALETTE
- EVERY_N_MILLISECONDS(intervalEveningToMorning) { // TRAVERSE THE COMPLETE PALETTE
- if (paletteIndex < 255) {
- paletteIndex++;
- }
- if (paletteIndex == 255) {
- paletteIndex = 0;
- }
- }
- Serial.println(colour); // MAY BE REMOVED AFTER TESTING
- }
- void dayCycle()
- {
- CRGB colour = ColorFromPalette(myPal2, paletteIndex, maxBrightness, LINEARBLEND);
- fill_solid(leds, NUM_LEDS, colour);
- EVERY_N_MILLISECONDS(intervalMorningToEvening) {
- if (paletteIndex < 255) {
- paletteIndex++;
- }
- if (paletteIndex == 255) {
- paletteIndex = 0;
- }
- }
- Serial.println(colour); // MAY BE REMOVED AFTER TESTING
- }
- //--------FADING LIGHTS---------
- void streetLightFading()
- {
- if (currentMillis - previousMillis >= timeBaseInterval)
- analogWrite(STREET_LED, brightness_STREET);
- analogWrite(STREET_LED2, brightness_STREET);
- brightness_STREET = brightness_STREET + fadeAmount;
- if (brightness_STREET <= 0 || brightness_STREET >= 255) {
- fadeAmount = -fadeAmount ;
- }
- delayMicroseconds(timeBaseInterval); //waits for "timeBaseInterval" to see the fading effect
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement