Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define FASTLED_INTERNAL
- #include <FastLED.h>
- int num = 1;
- int32_t interval = (int32_t) num * 100; /*num is an int, the calculation will done as an int and overflow.
- The (int32_t) casts (converts) to the larger type, so the result of the calculation
- fits and doesn't overflow.*/
- #define NUM_LEDS 15 // NUMBER OF PIXELS IN THE USED STRIP
- #define DATA_PIN 5
- byte maxBrightness = 155; // VALUES FROM 0 - 255 -> THE HIGHER, THE MORE Amps NEEDED - FOR THE LED STRIPS
- CRGB leds[NUM_LEDS];
- #define streetLights 2
- #define buildingLights 3
- int32_t ledTimer = 0;
- int32_t ledTimerUpdate = 0;
- DEFINE_GRADIENT_PALETTE (AM_gp) { // Midnight To Noon (amCycle)
- 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 (PM_gp) { // Noon to Midnight (pmCycle)
- 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
- };
- void setup() {
- Serial.begin(9600);
- FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS);
- pinMode(streetLights, OUTPUT);
- pinMode(buildingLights, OUTPUT);
- }
- uint8_t paletteIndex = 0;
- CRGBPalette16 currentPalette = AM_gp;
- uint8_t state = 0; // 0 for AM, 1 for PM
- void loop() {
- EVERY_N_MILLISECONDS(interval) {
- paletteIndex++;
- if (paletteIndex == 240) {
- paletteIndex = 0;
- state = 1 - state;
- currentPalette = state ? PM_gp : AM_gp;
- }
- CRGB color = ColorFromPalette(currentPalette, paletteIndex, maxBrightness, LINEARBLEND);
- fill_solid(leds, NUM_LEDS, color);
- FastLED.show();
- streetLightsRoutine();
- buildingLightsRoutine();
- }
- }
- //*************************************
- void streetLightsRoutine() {
- int32_t localInterval = 2 * 240 * interval;
- int32_t localTimer = millis() % localInterval;
- if ((localTimer >= .25 * localInterval) && (localTimer <= .75 * localInterval)) {
- digitalWrite(streetLights, LOW);
- } else {
- digitalWrite(streetLights, HIGH);
- }
- }
- void buildingLightsRoutine() {
- int32_t localInterval = 2 * 240 * interval;
- int32_t localTimer = millis() % localInterval;
- if ((localTimer >= .5 * localInterval) && (localTimer <= .75 * localInterval)) {
- digitalWrite(buildingLights, HIGH);
- } else {
- digitalWrite(buildingLights, LOW);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement