kartonman

event timer light fader

Dec 4th, 2024
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.90 KB | None | 0 0
  1. /*Event Timer Light Fader*/
  2. /*how to use this sketch and how to make the controlling circuit board is at
  3. https://steamtraininfo.com/for-modelers/arduino-projects/led-fade-up-fade-down */
  4.  
  5. #define streetSwitch A2 /*controls on and off function. */
  6.  
  7. /*Declartions for lights that will fade on and off. All are PWM pins. */
  8. int Light3 = 3;
  9. int Light5 = 5;
  10. int Light6 = 6;
  11. int Light9 = 9;
  12. int Light10 = 10;
  13. int Light11 = 11;
  14.  
  15. int valStreet = 0;
  16. int brightness = 0;
  17.  
  18. /* how many points to fade the LED by. A higher amount means the steps will be larger. */
  19. int fadeupAmount = 2;
  20. int fadedownAmount = 5;
  21.  
  22. /*these set the time between steps. So if you are making street lights, for example, you can have them, just like they do in the real world,
  23. fade on in small steps over a long time and have them fade off quickly.*/
  24. int stepupdelay = 150; /* slows the fade on time by setting time between steps in change of brightness set above */
  25. int stepdowndelay = 100; /* slows the fade off time by setting time between steps in change of brightness set above */
  26.  
  27.  
  28. void setup() {
  29. pinMode(Light3 , OUTPUT);
  30. pinMode(Light5 , OUTPUT);
  31. pinMode(Light6 , OUTPUT);
  32. pinMode(Light9 , OUTPUT);
  33. pinMode(Light10 , OUTPUT);
  34. pinMode(Light11 , OUTPUT);
  35. pinMode(streetSwitch, INPUT);
  36. }
  37.  
  38. void loop() {
  39. valStreet = digitalRead(streetSwitch);
  40. if (valStreet== HIGH) {
  41. analogWrite(Light3, brightness);// set the brightness of pin 3:
  42. analogWrite(Light5, brightness);// set the brightness of pin 5:
  43. analogWrite(Light6, brightness);// set the brightness of pin 6:
  44. analogWrite(Light9, brightness);// set the brightness of pin 9:
  45. analogWrite(Light10, brightness);// set the brightness of pin 10:
  46. analogWrite(Light11, brightness);// set the brightness of pin 11:
  47.  
  48. brightness = brightness + fadeupAmount; // change the brightness for next time through the loop:
  49.  
  50. delay(stepupdelay);/* slows the fade time by setting time between steps in change of brightness. change as you wish in declarations above */
  51. if (brightness >= 255) { // keeps the LEDS bright once they reach max brigthness
  52. brightness = 255;
  53. }
  54. }
  55.  
  56. if (valStreet == LOW) {
  57. analogWrite(Light3, brightness);// set the brightness of pin 3:
  58. analogWrite(Light5, brightness);// set the brightness of pin 5:
  59. analogWrite(Light6, brightness);// set the brightness of pin 6:
  60. analogWrite(Light9, brightness);// set the brightness of pin 9:
  61. analogWrite(Light10, brightness);// set the brightness of pin 10:
  62. analogWrite(Light11, brightness);// set the brightness of pin 11:
  63.  
  64. brightness = brightness - fadedownAmount; // change the brightness for next time through the loop:
  65. delay(stepdowndelay);/* slows the fade time by setting time between steps in change of brightness. change as you wish in declarations above */
  66.  
  67. if (brightness <= 0) {
  68. brightness = 0;
  69. }
  70. }
  71. }
  72.  
  73.  
Advertisement
Add Comment
Please, Sign In to add comment