Hi,
i'am doing a little project it's a reaction game,
there need to blink 5 leds like in knightrider and if you push the button when the led
in the middle is on the rgb led will turn green or else it will turn red.
but the leds are not blinking, i did check if the leds do work and, they work all.
so i'am asking for a little help.
here is the code:
const int button = 7;
const int ledg = 0;
const int ledr = 1;
const int led1 = 2;
const int led2 = 3;
const int led3 = 4;
const int led4 = 5;
const int led5 = 6;
int ledstate = 0;
int buttonstate = 0;
long previous = 0;
long interval = 1000;
int ledOn = 0;
void setup() {
pinMode(button, INPUT);
pinMode(ledg, OUTPUT);
pinMode(ledr, OUTPUT);
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(led4, OUTPUT);
pinMode(led5, OUTPUT);
}
void loop() {
ledstate = digitalRead(led3);
buttonstate = digitalRead(button);
unsigned long currentmillis = millis();
if (currentmillis == interval) {
ledOn + 1;
interval + 1000;
}
if (ledOn >= 7) {
ledOn = 0;
}
if (ledOn == 1) {
digitalWrite(led5, LOW);
digitalWrite(led1, HIGH);
}
if (ledOn == 2) {
digitalWrite(led1, LOW);
digitalWrite(led2, HIGH);
}
if (ledOn == 3) {
digitalWrite(led2, LOW);
digitalWrite(led3, HIGH);
}
if (ledOn == 4) {
digitalWrite(led3, LOW);
digitalWrite(led4, HIGH);
}
if (ledOn == 5) {
digitalWrite(led4, LOW);
digitalWrite(led5, HIGH);
}
if (buttonstate == HIGH && ledstate == HIGH) {
digitalWrite(ledg, HIGH);
delay(2000);
digitalWrite(ledg, LOW);
}
if (buttonstate == HIGH && ledstate == LOW) {
digitalWrite(ledr, HIGH);
delay(2000);
digitalWrite(ledr, LOW);
}
}