Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*Goods Shed Daily cycle. Set it to 3000 for the 1/2 hour cycle.
- This sketch created and copywrite by Gary C. Granai https://www.facebook.com/gary.granai and is included in the Arduino For Model Railing Library at https://steamtraininfo.com/arduino-projects
- You are free to use this sketch and amend it for your own personal use as long these credits remain intact.
- Using it in any manner or form for commercial purposes is prohibed.*/
- #define FASTLED_INTERNAL
- #include <FastLED.h>
- int num = 1; //an interval of 3000 lasts about 24.5 minutes real time
- int32_t interval = (int32_t) num * 500; /*num is an int, the calculation when done as an int and overflow.
- The (int32_t) converts it to the larger type, so the result of the calculation fits and doesn't overflow.*/
- #define NUM_LEDS 27 // NUMBER OF PIXELS IN THE USED STRIP
- #define DATA_PIN 6
- byte maxBrightness = 100; // VALUES FROM 0 - 255 -> THE HIGHER, THE MORE AMPS NEEDED FOR THE LED STRIP
- CRGB leds[NUM_LEDS];
- #define streetLights 2
- #define buildingLights 3
- #define securityLights 4
- int32_t ledTimer = 0;
- int32_t ledTimerUpdate = 0;
- //the colors and timing of the colors of the LEDs on the strip.
- DEFINE_GRADIENT_PALETTE (AM_gp) { // Midnight To Noon (amCycle)
- 0, 0, 0, 0, //black
- 5, 0, 0, 0, // Black
- 15, 0, 0, 0, //black
- 50, 0, 0, 0, //black
- 105, 97, 97, 79, //
- 127, 189, 143, 16, //
- 148, 239, 172, 0, //orange
- 169, 212, 202, 0, //dark yellow
- 200, 255, 253, 213, //bright yellow
- 232, 255, 255, 255, //white
- 255, 255, 255, 255, //white
- };
- DEFINE_GRADIENT_PALETTE (PM_gp) { // Noon to Midnight (pmCycle)
- 0, 255, 255, 255, //white
- 5, 255, 255, 255, //white
- 21, 255, 253, 213, //bright yellow
- 50, 212, 202, 0, //dark yellow
- 84, 239, 172, 0, //orange
- 105, 189, 143, 16, //
- 127, 97, 97, 79, //
- 148, 0, 0, 0, //black
- 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);
- pinMode(securityLights, OUTPUT);
- }
- uint8_t paletteIndex = 0;
- CRGBPalette16 currentPalette = AM_gp;
- uint8_t state = 0; // 0 for AM, 1 for PM
- //Routine
- //************************************************************************
- void loop() {
- EVERY_N_MILLISECONDS(interval) {
- paletteIndex++;
- if (paletteIndex == 240)/*Because a linear blend is being used, the index has to be set less than 255.
- If it is set at 255 there will be a discontinuity in the display of colors. Even, as in this case with 240
- selected, the linear blend take the index up to 255 and the full cycle displays on the LED strip.*/
- {
- 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();
- streetLightsCycle();
- buildingLightsCycle();
- securityLightsCycle();
- }
- }
- //Cycles
- //*************************************
- //street and track lighs
- void streetLightsCycle() {
- 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);
- }
- }
- //*************************************
- //building lights
- void buildingLightsCycle() {
- int32_t localInterval = 2 * 240 * interval;
- int32_t localTimer = millis() % localInterval;
- if ((localTimer >= .27 * localInterval) && (localTimer <= .7 * localInterval)) {
- digitalWrite(buildingLights, HIGH);
- } else {
- digitalWrite(buildingLights, LOW);
- }
- }
- //****************************************************
- //security lights
- void securityLightsCycle() {
- int32_t localInterval = 2 * 240 * interval;
- int32_t localTimer = millis() % localInterval;
- if ((localTimer <= .31 * localInterval) || (localTimer >= .81 * localInterval)) {
- digitalWrite(securityLights, HIGH);
- } else {
- digitalWrite(securityLights, LOW);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement