Hi all, first time poster. Looks like a ton of useful information and helpful people here. I'm a newby to the Ardino, but did some BASIC programming back in the 80's, so some of the code makes a little sense to this old fart.
I have an Elegoo Uno R3 starter kit and have a mock up of my project on a breadboard and the code copied below.
Here is my objective: I want to build a sort of traffic light (red, yellow, green) to use at autocrosses to stage drivers. The "normal" status will be red light on, green & yellow off. When a car activates a photo cell, red light goes off and yellow light comes on. When the starter presses a momentary button, the yellow and red light are off and the green light goes on and stays on for a short time (maybe 5 seconds), then returns to "normal" status of red light on, green and yellow off.
My mock up hardware and code kind of work. I hold down the miniature button to simulate a car staged. I then touch the "go" button and everything works as it's supposed to.
Here's my problem: I have two different photo cells. One is manufactured by ALGE and is normally open and goes to closed when the beam is blocked. If I replace the miniature button with this photocell, all is well. The other photocell is manufactured by TagHeuer and is normally open and only gives a momentary close when the beam is blocked. I would prefer to use the TagHeuer light for this project and save my ALGE light for my timing equipment.
I assume I need to code in a toggle function. I have played with that and watched a couple tutorials several times, but I just can't seem to figure out how to make all this work together.
My schematic is pretty simple - I'll draw a little neater one and post.
Thanks in advance for any help and please go gentle.
// constants won't change. They're used here to set pin numbers:
const int stagebuttonPin = 4; // the number of the pushbutton pins
const int gobuttonPin = 2;
const int redledPin = 12; // the number of the LED pins
const int yellowPin = 13;
const int grnPin = 11;
int stagebuttonState;
int gobuttonState;
void setup() {
pinMode(redledPin, OUTPUT); // initialize the LEDs pin as an output:
pinMode(yellowPin, OUTPUT);
pinMode(grnPin, OUTPUT);
pinMode(stagebuttonPin, INPUT); // initialize the pushbutton pin as an input:
pinMode(gobuttonPin, INPUT);
}
void loop() {
stagebuttonState = digitalRead(stagebuttonPin); // read the state of the pushbutton value:
gobuttonState = digitalRead(gobuttonPin);
if (stagebuttonState == 0 && gobuttonState == 0) { // normal state, red led on,
digitalWrite(redledPin, HIGH);
digitalWrite(yellowPin, LOW);
digitalWrite(grnPin, LOW);
}
if (stagebuttonState == 1 && gobuttonState == 0) { // staged state, yellow led on,
digitalWrite(redledPin, LOW);
digitalWrite(yellowPin, HIGH);
digitalWrite(grnPin, LOW);
}
if (stagebuttonState == 1 && gobuttonState == 1) { // go button pushed, grn led on for 5 secs, then back to normal state
digitalWrite(redledPin, LOW);
digitalWrite(yellowPin, LOW);
digitalWrite(grnPin, HIGH);
delay (5000);
digitalWrite(redledPin, HIGH);
digitalWrite(yellowPin, LOW);
digitalWrite(grnPin, LOW);
}
}

![20210120_155537[1].jpg](https://europe1.discourse-cdn.com/arduino/original/3X/9/c/9c6a7934dcdd46078883d05a033486c3919932be.jpg)