Loading...
Loading...
// Three-aspect signal controller
const int RED = 9;
const int YELLOW = 10;
const int GREEN = 11;
enum Aspect { STOP, APPROACH, CLEAR };
Aspect currentAspect = STOP;
void setup() {
pinMode(RED, OUTPUT);
pinMode(YELLOW, OUTPUT);
pinMode(GREEN, OUTPUT);
}
void setAspect(Aspect aspect) {
// Fade out current, fade in new
analogWrite(RED, aspect == STOP ? 255 : 0);
analogWrite(YELLOW, aspect == APPROACH ? 255 : 0);
analogWrite(GREEN, aspect == CLEAR ? 255 : 0);
}
void loop() {
setAspect(currentAspect);
delay(100);
}This is starter code - modify and expand for your specific needs.
Before building this project, make sure you have the Arduino IDE installed and are comfortable uploading basic sketches to your board.
Most projects use standard Arduino libraries. Some may require additional libraries like AccelStepper, Servo, or NmraDcc - install these through the Arduino Library Manager.