kartonman

Event Timer Kit Program

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