Hello everyone
I have a question about using the milli(s) expression.
i have the following code (might look familiar
);
```
int led1 = 1;
int led2 = 2;
int led3 = 3;
int led4 = 4;
int led5 = 5;
int led6 = 6;
int button = 8;
long drukTijd;
void setup(){
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(led4, OUTPUT);
pinMode(led5, OUTPUT);
pinMode(led6, OUTPUT);
pinMode(button, INPUT);
// start opstelling
digitalWrite(led1, HIGH);
digitalWrite(led6, HIGH);}
void loop()
{
int state = digitalRead(button);
if(state == HIGH && (millis() - drukTijd)> 5000)
{changeLights();}
}
void changeLights(){
digitalWrite(led1,LOW);
digitalWrite(led6,LOW);
digitalWrite(led3,HIGH);
digitalWrite(led4,HIGH);
delay (2000);
digitalWrite(led2,HIGH);
digitalWrite(led5,HIGH);
digitalWrite(led3,LOW);
digitalWrite(led4,LOW);
delay (2000);
digitalWrite(led1,HIGH);
digitalWrite(led6,HIGH);
digitalWrite(led2,LOW);
digitalWrite(led5,LOW);
delay (2000);
```
my question is about the following lines;
int state = digitalRead(button);
if(state == HIGH && (millis() - drukTijd)> 5000)
why does this work ? in my eyes im telling the program;
if button is high and (milliseconds - a number between -2147483648 ~ 2147483647) > 5000, and it works, how ? what am i really reffering to ?
so a unit of time - a number, converted to time compared to an amount of time.
also;
does this mean by typing drukTijd between the brackets with millis, i have now converted drukTijd to be an amount of time ? instead of being a counter, its now still a counter and i added the unit time to it?
side note:
it doesnt work as intended
if i load it up and press the button within 5 seconds it wont run,
then if i press the button after 5 seconds it runs as intended and i cant restart it by pressing the button again, which is what i want.
but, when the program runs, and finishes, i can start it again instantly, even when 5secs havnt passed, why is this ?
ive also adjusted the delays to 500, so the program is done after 1,5secs but i can still rerun it instantly, so what is wrong with my counter ?
how do i program it so that it can be pressed instantly, but wont re run within 5 seconds
thanks for your help in advance
