Rotating Scoring Machine Help

Hello All!

I am a very beginner programmer and need some help with a project I'm working on. The project is a Soccer game. There are 3 holes, each with a light and a switch. I'm also interfacing with an existing keyboard based scoring system, where the scores will increment via F1,F2,and F3. The holes/lights will rotate (1, then 2, then 3) and the user must score in the lit hole. The rotation will start upon a button press, and switch between two lights (Green for ready, Yellow for running)

I currently have the rotating lights and ready/running light status going. I need help with tracking if the light is lit, and sending the keyboard press. I'm using the Keyboard.h library

Also just to test I've commented out the keyboard stroke stuff and added a Serial.println to make sure the logic works.

I'm having a bit of a hard time getting the Serial Print to work. In theory, if the serial print works, I should be able to just substitute the keyboard strokes in.

Should I be using a wait or while function instead of an IF function to watch button presses while a light is lit? (Go easy on me, I'm a greenhorn with programming)

//#include "Keyboard.h"

const int start_button = 7; const int hole1switch = 8; const int hole1light = 4; const int hole2switch = 9; const int hole2light = 5; const int hole3switch = 10; const int gamereadylight = 11; const int gamerunninglight = 12; const int hole3light = 6; int start_button_state = 0; int hole1state = 0; int prevhole1state = HIGH; int hole2state = 0; int prevhole2state = HIGH; int hole3state = 0; int prevhole3state = HIGH; long debounceDelay = 50;

void setup() { // initialize digital pins as inputs or outputs pinMode(hole1light, OUTPUT); // Relay 1, LED Bank 1 pinMode(hole2light, OUTPUT); // Relay 2, LED Bank 2 pinMode(hole3light, OUTPUT); //Relay 3, LED Bank 3 pinMode(gamereadylight, OUTPUT); //Status Light Green, Game is ready pinMode(gamerunninglight, OUTPUT); //Status Light Red, Game is in process pinMode(start_button, INPUT_PULLUP); //Start button pinMode(hole1switch, INPUT_PULLUP); //Spring switch 1, 10pts digitalWrite(hole1switch, HIGH); pinMode(hole2switch, INPUT_PULLUP); //Spring switch 2, 20pts pinMode(hole3switch, INPUT_PULLUP); //Spring switch 3, 30pts // Keyboard.begin(); Serial.begin(9600);

}

// the loop function runs over and over again forever void loop() {

int start_button_state = digitalRead(start_button); int hole1state = digitalRead(hole1switch); int hole2state = digitalRead(hole2switch); int hole3state = digitalRead(hole3switch);

if (start_button_state == HIGH) { digitalWrite(gamereadylight, LOW); // turn off game ready light digitalWrite(gamerunninglight, HIGH); // turn on game running light digitalWrite(hole1light, HIGH); // turn the Relay 1 on (HIGH is the voltage level) delay(5000); // wait for 5 seconds if((digitalRead(hole1light) == HIGH) && (hole1state == HIGH) && (hole1state != prevhole1state)) { // Keyboard.press(KEY_F1); // If Hole 1 light is on, and the switch activates, Press F1 on the keyboard Serial.println('KEY_F1'); delay(100); // Keyboard.releaseAll(); } prevhole1state == hole1state; digitalWrite(hole1light, LOW); // turn the Relay 1 off by making the voltage LOW delay(100); // wait for a 100th of a second digitalWrite(hole2light, HIGH); // turn the Relay 2 on (HIGH is the voltage level) delay(5000); // wait for 5 seconds digitalWrite(hole2light, LOW); // turn the Relay 2 off by making the voltage LOW delay(100); // wait for a 100th of a second digitalWrite(hole3light, HIGH); // turn the Relay 3 on (HIGH is the voltage level) delay(5000); // wait for 5 seconds digitalWrite(hole3light, LOW); // turn the Relay 3 off by making the voltage LOW delay(100); // wait for a 100th of a second digitalWrite(gamereadylight, HIGH); //Turn on game ready light digitalWrite(gamerunninglight, LOW); //Turn off game running light digitalWrite(start_button_state, LOW); //set start button state to low }

else { digitalWrite(gamereadylight, HIGH); //keep game ready light on }}

Thank you all in advanced!

Show us a good schematic of your circuit.
Show us a good image of your wiring.
Give links to components.
Posting images:

Use CTRL T to format your code.
Attach your sketch between code tags
[code]Paste your sketch here[/code]

Lose all those delay()s, use BWD Blink Without Delay techniques.
See Robin2’s discussion:

Also, try to follow these:

Scan your switches every ~50ms and look for change in state detection instead of operating on current switch level conditions.

I like Nick Gammons ‘switchmanager’ to handle switches as discussed here: