kartonman

Goods Shed Light Fader

Feb 23rd, 2022 (edited)
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.25 KB | None | 0 0
  1. /*The street and track lights fader cycle for the goods shed.
  2. This sketch created and copywrite by Gary C. Granai https://www.facebook.com/gary.granai and is included in the
  3. Arduino For Model Railing Library at https://steamtraininfo.com/arduino-projects
  4. You are free to use this sketch and amend it for your own personal use as long as these credits remain intact.
  5. Using it in any manner or form for commercial purposes is prohibed.*/
  6.  
  7. #define streetSwitch A5
  8. #define streetEast 6 /* fading lights must be attached to pwm pins. Since there are only 6 pwm pins
  9. on a nano/uno, to fade more lights use TLC 5940 https://steamtraininfo.com/arduino-projects/arduino-tlc5940
  10. */
  11. #define streetWest 9
  12. #define trackEast 10
  13. #define trackWest 11
  14. int brightness = 0; //
  15. int fadeAmount = 5; // how many points to fade the LED by . will be slowed by a delay in the loop.
  16. int val = 0;
  17.  
  18. // the setup routine runs once when you press reset:
  19. void setup() {
  20. // declare pwm pins to be output:
  21. pinMode(streetEast, OUTPUT);
  22. pinMode(streetWest, OUTPUT);
  23. pinMode(trackEast, OUTPUT);
  24. pinMode(trackWest, OUTPUT);
  25.  
  26. pinMode(streetSwitch, INPUT);
  27. }
  28.  
  29. //Routine
  30. void loop() {
  31. lights();
  32. }
  33.  
  34. //Cycles
  35. //******************************************************************
  36. void lights(){
  37. val = digitalRead(streetSwitch); // read the signal from the daily cycle
  38.  
  39. if (val == HIGH) {
  40. analogWrite(streetEast, brightness);// set the brightness of pin :
  41. analogWrite(streetWest, brightness);
  42. analogWrite(trackEast, brightness);
  43. analogWrite(trackWest, brightness);
  44.  
  45.  
  46. brightness = brightness + fadeAmount; // change the brightness for next time through the loop:
  47. delay(200);// slows the fade time }
  48.  
  49. if (brightness >= 255) { // keeps the LEDS bright once they reach max brigthness
  50. brightness = 255;
  51. }
  52. }
  53.  
  54. if (val == LOW) {
  55. analogWrite(streetEast, brightness);// set the brightness of pin 9:
  56. analogWrite(streetWest, brightness);
  57. analogWrite(trackEast, brightness);
  58. analogWrite(trackWest, brightness);
  59.  
  60.  
  61.  
  62. brightness = brightness - fadeAmount; // change the brightness for next time through the loop:
  63. delay(100);// slows the fade time }
  64. if (brightness <= 0) {
  65. brightness = 0;
  66. }
  67. }
  68. }
  69.  
Add Comment
Please, Sign In to add comment