So i have a simple circuit (I'm new) and i' making a traffic light system which will turn on when you press a button. But when i press the button i don't think anything happens and pressed or not pressed the lights follow the code after an amount of seconds. The circuit is not the problem and im using 220 resistors and specifically for the button i have used a 10k resistor and a 220 resistor. the arduino is not damaged and im following (kind of) from here
Going Deeper: Arduino Pedestrian Crossing, the circuit looks like this (second image)
(the only difference is that the lights will activate automatically after a fixed amount of seconds (unknown))
int redLED = 10;
int yellowLED = 9;
int greenLED = 8;
int buttonPIN = 12;
int buttonPINValue = 0;
//runs at start
void setup() {
pinMode(redLED, OUTPUT);
pinMode(yellowLED, OUTPUT);
pinMode(greenLED, OUTPUT);
pinMode(buttonPIN, INPUT);
}
//constantly runs
void loop(){
allBlink();
changeLights();
}
//cross lights colour
void changeLights(){
digitalWrite(greenLED, LOW);
digitalWrite(yellowLED, HIGH);
delay(2000);
digitalWrite(yellowLED, LOW);
digitalWrite(redLED, HIGH);
delay(2000);
digitalWrite(yellowLED, HIGH);
delay(2000);
digitalWrite(yellowLED, LOW);
digitalWrite(redLED, LOW);
digitalWrite(greenLED, HIGH);
delay(2000);
digitalWrite(greenLED, LOW);
}
//all lights blink before start
void allBlink(){
for (int i = 0; i < 3; i++) {
digitalWrite(yellowLED, HIGH);
digitalWrite(redLED, HIGH);
digitalWrite(greenLED, HIGH);
delay(100);
digitalWrite(yellowLED, LOW);
digitalWrite(redLED, LOW);
digitalWrite(greenLED, LOW);
delay(100);
}
}
void buttonPress(){
buttonPINValue = digitalRead(buttonPIN);
if(buttonPINValue == HIGH){
allBlink();
changeLights();
buttonPINValue = LOW;
}
}
(thank you in advance)