The board I'm using is the Sparkfun Redboard Qwiic.
Here's the sketch, inputs are analog inputs, not digital.
Inputs come from double throw, center off toggles which connect to either 5V or GND.
/*****************************************************************
The line inputs are treated as binary digits to select eight
possible conditions which are passed to the light outputs.
EH ED EFD RESULT
Case 0 = 0 0 0 RED SIGNAL
Case 1 = 0 0 1 RED SIGNAL
Case 2 = 0 1 0 RED SIGNAL
Case 3 = 0 1 1 RED SIGNAL
Case 4 = 1 0 0 YELLOW SIGNAL
Case 5 = 1 0 1 FLASHING YELLOW SIGNAL
Case 6 = 1 1 0 GREEN SIGNAL
Case 7 = 1 1 1 GREEN SIGNAL
*****************************************************************/
// Define the line circuit input pins
// Use pulldown resistors on these inputs
const int EH = A0; // H line input for eastward moves
const int ED = A1; // D line input for eastward moves
const int EFD = A2; // FD line input for eastward moves
// Define the signal output pins
const int ERE = 13; // Eastward signal Red LED output
const int EYE = 12; // Eastward signal Yellow LED output
const int EGE = 11; // Eastward signal Green LED output
void setup() {
pinMode(EGE, OUTPUT); // Green LED
pinMode(EYE, OUTPUT); // Yellow LED
pinMode(ERE, OUTPUT); // Red LED
pinMode(EH, INPUT); // H toggle switch
pinMode(ED, INPUT); // D toggle switch
pinMode(EFD, INPUT); // FD toggle switch
}
void loop() {
// The variable "input"
// is a 3-bit binary number.
// Bit 0 is read from the FD input,
// bit 1 from the D input and
// bit 2 from the H input.
int input;
bitWrite(input, 0, digitalRead(EFD)); // Read all line
bitWrite(input, 1, digitalRead(ED)); // inputs into
bitWrite(input, 2, digitalRead(EH)); // "input" variable
switch (input)
{
case 0:
digitalWrite(EGE, LOW);
digitalWrite(EYE, LOW);
digitalWrite(ERE, HIGH);
break;
case 1: // Signal aspect is RED
digitalWrite(EGE, LOW);
digitalWrite(EYE, LOW);
digitalWrite(ERE, HIGH);
break;
case 2: // Signal aspect is RED
digitalWrite(EGE, LOW);
digitalWrite(EYE, LOW);
digitalWrite(ERE, HIGH);
break;
case 3: //Signal aspect is RED
digitalWrite(EGE, LOW);
digitalWrite(EYE, LOW);
digitalWrite(ERE, HIGH);
break;
case 4: // Signal aspect is YELLOW
digitalWrite(EGE, LOW);
digitalWrite(EYE, HIGH);
digitalWrite(ERE, LOW);
break;
case 5: // Signal aspect is YELLOW
digitalWrite(EGE, LOW);
digitalWrite(EYE, HIGH);
digitalWrite(ERE, LOW);
break;
case 6: // Signal aspect is FLASHING YELLOW
digitalWrite(EGE, LOW);
digitalWrite(ERE, LOW);
digitalWrite(EYE, HIGH);
delay(500);
digitalWrite(EYE, LOW);
delay(500);
break;
case 7: // Signal aspect is GREEN
digitalWrite(EGE, HIGH);
digitalWrite(EYE, LOW);
digitalWrite(ERE, LOW);
break;
}
}