Hi, Im making turn counter for a 2 player game(BloodBowl)
My intention is that every time the player hits the button an LED will turn on.
I have this working for Red Player
Im not sure how to program the second button (ButtonBlueTurn) to control a 2nd set of LEDs, as the different integer states are already controlled by the first player (ButtonRedTurn and red LEDs)
#define ButtonRedTurn 40 //Red players Turn button
#define ButtonBlueTurn 30 //Blue Players Turn Button
#define redT1 41 //
#define redT2 42 //
#define redT3 43 //
#define redT4 44 //
#define blueT1 31
int state = 0; //integer to hold current state
int old = 0; //integer to hold last state
int ButtonRedTurnPoll = 0; //integer to hold button state
void setup() {
pinMode(ButtonRedTurn,INPUT); // button set as input
pinMode(redT1,OUTPUT); //LEDs set as outputs
pinMode(redT2,OUTPUT);
pinMode(redT3,OUTPUT);
pinMode(redT4,OUTPUT);
pinMode(blueT1,OUTPUT);
digitalWrite(redT1,LOW); //set initial state as off
digitalWrite(redT2,LOW);
digitalWrite(redT3,LOW);
digitalWrite(redT4,LOW);
digitalWrite(blueT1,LOW);
}
void loop() {
//debouncing routine to read button
ButtonRedTurnPoll = digitalRead(ButtonRedTurn); //poll state of button
if(ButtonRedTurnPoll == 1) {
delay(50); //wait 50ms
ButtonRedTurnPoll = digitalRead(ButtonRedTurn); //poll button again
if(ButtonRedTurnPoll == 0) {
state = old + 1;
} }
else {
delay(100);
}
switch (state) { //react to button press and state
case 1:
digitalWrite(redT1,HIGH);
digitalWrite(blueT1,HIGH);
old = state;
break;
case 2:
digitalWrite(redT2,HIGH);
old = state;
break;
case 3:
digitalWrite(redT3,HIGH);
old = state;
break;
case 4:
digitalWrite(redT4,HIGH);
old = state;
break;
default: //if state not 1 2 or 3
digitalWrite(redT1,LOW);
digitalWrite(redT2,LOW);
digitalWrite(redT3,LOW);
digitalWrite(redT4,LOW);
digitalWrite(blueT1,LOW);
old = 0;
break;
}}
LightsSequence_Red_TurnCounter_Add_Second_B_copy_20230930171528.ino (1.6 KB)