Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*The street and track lights fader cycle for the goods shed.
- This sketch created and copywrite by Gary C. Granai https://www.facebook.com/gary.granai and is included in the
- Arduino For Model Railing Library at https://steamtraininfo.com/arduino-projects
- You are free to use this sketch and amend it for your own personal use as long as these credits remain intact.
- Using it in any manner or form for commercial purposes is prohibed.*/
- #define streetSwitch A5
- #define streetEast 6 /* fading lights must be attached to pwm pins. Since there are only 6 pwm pins
- on a nano/uno, to fade more lights use TLC 5940 https://steamtraininfo.com/arduino-projects/arduino-tlc5940
- */
- #define streetWest 9
- #define trackEast 10
- #define trackWest 11
- int brightness = 0; //
- int fadeAmount = 5; // how many points to fade the LED by . will be slowed by a delay in the loop.
- int val = 0;
- // the setup routine runs once when you press reset:
- void setup() {
- // declare pwm pins to be output:
- pinMode(streetEast, OUTPUT);
- pinMode(streetWest, OUTPUT);
- pinMode(trackEast, OUTPUT);
- pinMode(trackWest, OUTPUT);
- pinMode(streetSwitch, INPUT);
- }
- //Routine
- void loop() {
- lights();
- }
- //Cycles
- //******************************************************************
- void lights(){
- val = digitalRead(streetSwitch); // read the signal from the daily cycle
- if (val == HIGH) {
- analogWrite(streetEast, brightness);// set the brightness of pin :
- analogWrite(streetWest, brightness);
- analogWrite(trackEast, brightness);
- analogWrite(trackWest, brightness);
- brightness = brightness + fadeAmount; // change the brightness for next time through the loop:
- delay(200);// slows the fade time }
- if (brightness >= 255) { // keeps the LEDS bright once they reach max brigthness
- brightness = 255;
- }
- }
- if (val == LOW) {
- analogWrite(streetEast, brightness);// set the brightness of pin 9:
- analogWrite(streetWest, brightness);
- analogWrite(trackEast, brightness);
- analogWrite(trackWest, brightness);
- brightness = brightness - fadeAmount; // change the brightness for next time through the loop:
- delay(100);// slows the fade time }
- if (brightness <= 0) {
- brightness = 0;
- }
- }
- }
Add Comment
Please, Sign In to add comment