Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*lococargo special event timer 17 sept*/
- #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 /* change as necessary to match the NUMBER OF PIXELS IN YOUR 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 mainbuildingLights 3 /*main building*/
- #define mainsecurityLights 4 /*alongside main building*/
- #define coalyardsoundwithLights 5 /*coalyard*/
- #define generalbackgroundSounds 7 /*daytime general sounds*/
- #define shedlightswithsounds 8 /*during work hours*/
- #define streetLights 9 /*street lighting was 2 but changed to fit board*/
- #define backgroundsounds2 10 /* background sounds2*/
- 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(DATA_PIN, OUTPUT); /* added for test*/
- pinMode(streetLights, OUTPUT); /* street lights*/
- pinMode(mainbuildingLights, OUTPUT); /*main building*/
- pinMode(mainsecurityLights, OUTPUT); /*alongside main building*/
- pinMode(coalyardsoundwithLights, OUTPUT); /*coalyard*/
- pinMode(generalbackgroundSounds, OUTPUT); /*daytime general sounds*/
- pinMode(shedlightswithsounds, OUTPUT); /*during working hours*/
- pinMode(backgroundsounds2, OUTPUT); /*24 hour background sounds*/
- }
- 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(); /* street lighting */
- mainbuildingLightsCycle(); /* main building*/
- mainsecurityLightsCycle(); /*alongside main building*/
- coalyardsoundwithLightsCycle(); /*coalyard*/
- generalbackgroundSoundsCycle(); /*daytime general sounds*/
- shedlightswithsoundsCycle(); /* during working hours */
- backgroundsounds2Cycle(); /*wind and other semi-continuous sounds*/
- }
- }
- /*Cycles*/
- //*************************************
- /* 1 fades lights on and off*/
- 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);
- }
- }
- //****************************************************
- /* 2 turns security lights on and off*/
- void mainsecurityLightsCycle() {
- int32_t localInterval = 2 * 240 * interval;
- int32_t localTimer = millis() % localInterval;
- if ((localTimer <= .31 * localInterval) || (localTimer >= .81 * localInterval)) {
- digitalWrite(mainsecurityLights, HIGH);
- } else {
- digitalWrite(mainsecurityLights, LOW);
- }
- }
- //*************************************
- /* 3 turns main building lights on and off*/
- void mainbuildingLightsCycle() {
- int32_t localInterval = 2 * 240 * interval;
- int32_t localTimer = millis() % localInterval;
- if ((localTimer >= .27 * localInterval) && (localTimer <= .7 * localInterval)) {
- digitalWrite(mainbuildingLights, HIGH);
- } else {
- digitalWrite(mainbuildingLights, LOW);
- }
- }
- //*************************************
- /* 4 turns coalyard lights and associated background sounds on and off */
- void coalyardsoundwithLightsCycle() {
- int32_t localInterval = 2 * 240 * interval;
- int32_t localTimer = millis() % localInterval;
- if ((localTimer >= .27 * localInterval) && (localTimer <= .7 * localInterval)) {
- digitalWrite(coalyardsoundwithLights, HIGH);
- } else {
- digitalWrite(coalyardsoundwithLights, LOW);
- }
- }
- //*************************************
- /* 5 turns general background sounds on and off */
- void generalbackgroundSoundsCycle() {
- int32_t localInterval = 2 * 240 * interval;
- int32_t localTimer = millis() % localInterval;
- if ((localTimer >= .27 * localInterval) && (localTimer <= .7 * localInterval)) {
- digitalWrite(generalbackgroundSounds, HIGH);
- } else {
- digitalWrite(generalbackgroundSounds, LOW);
- }
- }
- //*************************************
- //7 turns sheds scene lights and background sounds on and off
- void shedlightswithsoundsCycle() {
- int32_t localInterval = 2 * 240 * interval;
- int32_t localTimer = millis() % localInterval;
- if ((localTimer >= .27 * localInterval) && (localTimer <= .7 * localInterval)) {
- digitalWrite(shedlightswithsounds, HIGH);
- } else {
- digitalWrite(shedlightswithsounds, LOW);
- }
- }
- //*************************************
- //8 turns semi-continuous background sounds on and off */
- void backgroundsounds2Cycle() {
- int32_t localInterval = 2 * 240 * interval;
- int32_t localTimer = millis() % localInterval;
- if ((localTimer >= .27 * localInterval) && (localTimer <= .7 * localInterval)) {
- digitalWrite(backgroundsounds2, HIGH);
- } else {
- digitalWrite(backgroundsounds2, LOW);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment