please help with mey arduino code

hello,

I am pretty new in programming with c. i got a arduino and i have to make a tutorial for my study. I already made a code but it does not seems to work the way I want.

i got LED 1 to 6 first 1=ON then 2=ON and 1=OFF then 3=ON and 2=OFF ETC until 6 then led6 wil stay on until i push the button. then 6=OFF and 5=ON than 5=OFF and 4=ON ETC until 1 and then every thing starts over. the lights are working fine, but my button is not working at all it keep going from 1 to 6 an back. this is my code.


const int led1 = 1;
const int led2 = 2;
const int led3 = 3;
const int led4 = 4;
const int led5 = 5;
const int led6 = 6;
const int drukknop = 7;

int statusled6 = 0; // when led6 is HIGH the statusled6 turns to one
int buttonState = 0; // when the button is getting pust the state turns to HIGH

void setup() {
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(led4, OUTPUT);
pinMode(led5, OUTPUT);
pinMode(led6, OUTPUT);
pinMode(drukknop, INPUT);
}
void loop() {{
statusled6 = digitalRead(led6); // when led6 is HIGH the statusled6 turns to one
buttonState = digitalRead(drukknop); // when the button is getting pust the state turns to HIGH
digitalWrite (led1, HIGH);
delay (1000);
digitalWrite (led1, LOW);
digitalWrite (led2, HIGH);
delay (1000);
digitalWrite (led2, LOW);
digitalWrite (led3, HIGH);
delay (1000);
digitalWrite (led3, LOW);
digitalWrite (led4, HIGH);
delay (1000);
digitalWrite (led4, LOW);
digitalWrite (led5, HIGH);
delay (1000);
digitalWrite (led5, LOW);
digitalWrite (led6, HIGH);
delay(1000);

} if (buttonState == HIGH && statusled6 == HIGH);{ //if the button turns to one and led6 is on then the program continues.

digitalWrite (led6, LOW);
digitalWrite (led5, HIGH);
delay (1000);
digitalWrite (led5, LOW);
digitalWrite (led4, HIGH);
delay (1000);
digitalWrite (led4, LOW);
digitalWrite (led3, HIGH);
delay (1000);
digitalWrite (led3, LOW);
digitalWrite (led2, HIGH);
delay (1000);
digitalWrite (led2, LOW);
digitalWrite (led1, HIGH);
}
}
if (buttonState == HIGH && statusled6 == HIGH);

Firstly, notice that you've put a semi-colon after the condition. Control statements in C++ aren't terminated with a semi colon. So remove the semi-colon.

Lastly, statusled6 == HIGH has no use in the condition. It won't help you verify that the hardware is working. It will just tell you that statusled6 was set to HIGH by the program. There's no need to verify that because you set it to HIGH right before the statement.
Topic archived. No new replies allowed.