Loading...
Loading...
// RGB Signal Mast
const int RED = 3, YELLOW = 5, GREEN = 6;
const int BLOCK_AHEAD = 2;
const int BLOCK_NEXT = 4;
void setup() {
pinMode(RED, OUTPUT);
pinMode(YELLOW, OUTPUT);
pinMode(GREEN, OUTPUT);
pinMode(BLOCK_AHEAD, INPUT_PULLUP);
pinMode(BLOCK_NEXT, INPUT_PULLUP);
}
void setSignal(int r, int y, int g) {
analogWrite(RED, r);
analogWrite(YELLOW, y);
analogWrite(GREEN, g);
}
void loop() {
if (digitalRead(BLOCK_AHEAD) == LOW) {
setSignal(255, 0, 0); // Red - block occupied
} else if (digitalRead(BLOCK_NEXT) == LOW) {
setSignal(0, 255, 0); // Yellow - approach
} else {
setSignal(0, 0, 255); // Green - clear
}
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.