Help with integers

Hi,

I just picked up a Arduino starter kit and completed some of the project in the book.

I wanted to try something for myself, but am a bit stuck on the code.

Here is what I want to do :

I have 3 buttons and 3 LED (1 green (pin 3) and two red ones (pin 4,5)

the buttons are on pins 8,9,10.

I put in a code so the two red LED blink as long as the buttons are nog pushed a certain amount of times.

In this example this is 3x button 1, 2x button 2 and 4x button 3.

When this is completed the green LED should light up.

For some reason, the green LED doesn’t light up.

I think the variables I have declared (Code1, Code2, Code3) don’t count up the number of times I push the button.

Can anyone point me in the right direction?

Thanks in advance

int switchState1 = 0;
int switchState2 = 0;
int switchState3 = 0;
int Code1 = 0;
int Code2 = 0;
int Code3 = 0;

void setup(){
  pinMode(3,OUTPUT);
  pinMode(4,OUTPUT);
  pinMode(5,OUTPUT);
  pinMode(8,INPUT);
  pinMode(9,INPUT);
  pinMode(10,INPUT);
  
}

void loop(){
  switchState1 = digitalRead(8);
  switchState2 = digitalRead(9);
  switchState3 = digitalRead(10);
  
if ((Code1 == 3) && (Code2 == 2) && (Code3 == 4)) {
  digitalWrite(3,HIGH);
}

else if (switchState1 == HIGH) {
  Code1 = Code1 + 1;
}

else if (switchState2 == HIGH) {
  Code2 = Code2 + 1;
}

else if (switchState3 == HIGH) {
  Code3 = Code3 + 1;
}
 

else {
  digitalWrite(3, LOW);
  digitalWrite(4, LOW);
  digitalWrite(5, HIGH);
  
  delay(100);
  digitalWrite(4, HIGH);
  digitalWrite(5, LOW);
  delay(100);
}
}

Consider how fast “loop()” runs.

You need to detect the transition from “not pushed” to “pushed”, not “is the button pushed”.

Check the examples in the IDE.