kartonman

lococargo event timer

Nov 17th, 2024
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.61 KB | None | 0 0
  1. /*lococargo special event timer 17 sept*/
  2.  
  3.  
  4. #define FASTLED_INTERNAL
  5. #include <FastLED.h>
  6.  
  7. int num = 1; /*an interval of 3000 lasts about 24.5 minutes real time.*/
  8. int32_t interval = (int32_t) num * 500; /*num is an int, the calculation when done as an int and overflow.
  9. The (int32_t) converts it to the larger type, so the result of the calculation fits and doesn't overflow.*/
  10.  
  11. #define NUM_LEDS 27 /* change as necessary to match the NUMBER OF PIXELS IN YOUR USED STRIP*/
  12. #define DATA_PIN 6
  13. byte maxBrightness = 100; /* VALUES FROM 0 - 255 -> THE HIGHER, THE MORE AMPS NEEDED FOR THE LED STRIP*/
  14. CRGB leds[NUM_LEDS];
  15.  
  16.  
  17. #define mainbuildingLights 3 /*main building*/
  18. #define mainsecurityLights 4 /*alongside main building*/
  19. #define coalyardsoundwithLights 5 /*coalyard*/
  20. #define generalbackgroundSounds 7 /*daytime general sounds*/
  21. #define shedlightswithsounds 8 /*during work hours*/
  22. #define streetLights 9 /*street lighting was 2 but changed to fit board*/
  23. #define backgroundsounds2 10 /* background sounds2*/
  24.  
  25.  
  26. int32_t ledTimer = 0;
  27. int32_t ledTimerUpdate = 0;
  28.  
  29.  
  30. /*the colors and timing of the colors of the LEDs on the strip.*/
  31. DEFINE_GRADIENT_PALETTE (AM_gp) { /* Midnight To Noon (amCycle)*/
  32. 0, 0, 0, 0, //black
  33. 5, 0, 0, 0, // Black
  34. 15, 0, 0, 0, //black
  35. 50, 0, 0, 0, //black
  36. 105, 97, 97, 79, //
  37. 127, 189, 143, 16, //
  38. 148, 239, 172, 0, //orange
  39. 169, 212, 202, 0, //dark yellow
  40. 200, 255, 253, 213, //bright yellow
  41. 232, 255, 255, 255, //white
  42. 255, 255, 255, 255, //white
  43. };
  44. DEFINE_GRADIENT_PALETTE (PM_gp) { /* Noon to Midnight (pmCycle)*/
  45. 0, 255, 255, 255, //white
  46. 5, 255, 255, 255, //white
  47. 21, 255, 253, 213, //bright yellow
  48. 50, 212, 202, 0, //dark yellow
  49. 84, 239, 172, 0, //orange
  50. 105, 189, 143, 16, //
  51. 127, 97, 97, 79, //
  52. 148, 0, 0, 0, //black
  53. 255, 0, 0, 0, //black
  54. };
  55.  
  56.  
  57.  
  58. void setup() {
  59. Serial.begin(9600);
  60. FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS);
  61. pinMode(DATA_PIN, OUTPUT); /* added for test*/
  62. pinMode(streetLights, OUTPUT); /* street lights*/
  63. pinMode(mainbuildingLights, OUTPUT); /*main building*/
  64. pinMode(mainsecurityLights, OUTPUT); /*alongside main building*/
  65. pinMode(coalyardsoundwithLights, OUTPUT); /*coalyard*/
  66. pinMode(generalbackgroundSounds, OUTPUT); /*daytime general sounds*/
  67. pinMode(shedlightswithsounds, OUTPUT); /*during working hours*/
  68. pinMode(backgroundsounds2, OUTPUT); /*24 hour background sounds*/
  69. }
  70.  
  71. uint8_t paletteIndex = 0;
  72. CRGBPalette16 currentPalette = AM_gp;
  73. uint8_t state = 0; // 0 for AM, 1 for PM
  74.  
  75. //Routine
  76. //************************************************************************
  77. void loop() {
  78. EVERY_N_MILLISECONDS(interval) {
  79. paletteIndex++;
  80. if (paletteIndex == 240)/*Because a linear blend is being used, the index has to be set less than 255.
  81. If it is set at 255 there will be a discontinuity in the display of colors. Even, as in this case with 240
  82. selected, the linear blend take the index up to 255 and the full cycle displays on the LED strip.*/
  83. {
  84. paletteIndex = 0;
  85. state = 1 - state;
  86. currentPalette = state ? PM_gp : AM_gp;
  87. }
  88. CRGB color = ColorFromPalette(currentPalette, paletteIndex, maxBrightness, LINEARBLEND);
  89. fill_solid(leds, NUM_LEDS, color);
  90. FastLED.show();
  91. streetLightsCycle(); /* street lighting */
  92. mainbuildingLightsCycle(); /* main building*/
  93. mainsecurityLightsCycle(); /*alongside main building*/
  94. coalyardsoundwithLightsCycle(); /*coalyard*/
  95. generalbackgroundSoundsCycle(); /*daytime general sounds*/
  96. shedlightswithsoundsCycle(); /* during working hours */
  97.  
  98. backgroundsounds2Cycle(); /*wind and other semi-continuous sounds*/
  99.  
  100. }
  101.  
  102. }
  103.  
  104. /*Cycles*/
  105. //*************************************
  106. /* 1 fades lights on and off*/
  107. void streetLightsCycle() {
  108. int32_t localInterval = 2 * 240 * interval;
  109. int32_t localTimer = millis() % localInterval;
  110. if ((localTimer >= .25 * localInterval) && (localTimer <= .75 * localInterval)) {
  111. digitalWrite(streetLights, LOW);
  112. } else {
  113. digitalWrite(streetLights, HIGH);
  114. }
  115. }
  116.  
  117.  
  118. //****************************************************
  119.  
  120. /* 2 turns security lights on and off*/
  121. void mainsecurityLightsCycle() {
  122. int32_t localInterval = 2 * 240 * interval;
  123. int32_t localTimer = millis() % localInterval;
  124. if ((localTimer <= .31 * localInterval) || (localTimer >= .81 * localInterval)) {
  125. digitalWrite(mainsecurityLights, HIGH);
  126. } else {
  127. digitalWrite(mainsecurityLights, LOW);
  128. }
  129. }
  130.  
  131.  
  132. //*************************************
  133. /* 3 turns main building lights on and off*/
  134. void mainbuildingLightsCycle() {
  135. int32_t localInterval = 2 * 240 * interval;
  136. int32_t localTimer = millis() % localInterval;
  137. if ((localTimer >= .27 * localInterval) && (localTimer <= .7 * localInterval)) {
  138. digitalWrite(mainbuildingLights, HIGH);
  139. } else {
  140. digitalWrite(mainbuildingLights, LOW);
  141. }
  142. }
  143.  
  144. //*************************************
  145. /* 4 turns coalyard lights and associated background sounds on and off */
  146. void coalyardsoundwithLightsCycle() {
  147. int32_t localInterval = 2 * 240 * interval;
  148. int32_t localTimer = millis() % localInterval;
  149. if ((localTimer >= .27 * localInterval) && (localTimer <= .7 * localInterval)) {
  150. digitalWrite(coalyardsoundwithLights, HIGH);
  151. } else {
  152. digitalWrite(coalyardsoundwithLights, LOW);
  153. }
  154. }
  155. //*************************************
  156. /* 5 turns general background sounds on and off */
  157. void generalbackgroundSoundsCycle() {
  158. int32_t localInterval = 2 * 240 * interval;
  159. int32_t localTimer = millis() % localInterval;
  160. if ((localTimer >= .27 * localInterval) && (localTimer <= .7 * localInterval)) {
  161. digitalWrite(generalbackgroundSounds, HIGH);
  162. } else {
  163. digitalWrite(generalbackgroundSounds, LOW);
  164. }
  165. }
  166.  
  167.  
  168.  
  169. //*************************************
  170. //7 turns sheds scene lights and background sounds on and off
  171. void shedlightswithsoundsCycle() {
  172. int32_t localInterval = 2 * 240 * interval;
  173. int32_t localTimer = millis() % localInterval;
  174. if ((localTimer >= .27 * localInterval) && (localTimer <= .7 * localInterval)) {
  175. digitalWrite(shedlightswithsounds, HIGH);
  176. } else {
  177. digitalWrite(shedlightswithsounds, LOW);
  178. }
  179. }
  180.  
  181. //*************************************
  182. //8 turns semi-continuous background sounds on and off */
  183. void backgroundsounds2Cycle() {
  184. int32_t localInterval = 2 * 240 * interval;
  185. int32_t localTimer = millis() % localInterval;
  186. if ((localTimer >= .27 * localInterval) && (localTimer <= .7 * localInterval)) {
  187. digitalWrite(backgroundsounds2, HIGH);
  188. } else {
  189. digitalWrite(backgroundsounds2, LOW);
  190. }
  191. }
  192.  
  193.  
  194.  
  195.  
  196.  
Advertisement
Add Comment
Please, Sign In to add comment