Hello. This is my first post here so dont judge me and help me out if I did anything wrong.
I am working on a drag racing light system and currently I am making little segments (programs) individualy and later I will put them all together to work. While working on one segment I am experiencing a problem with millis. This is actually my first time working with millis, and I did good on basic examples of millis function, but now it seems like Im stuck.
I want the first LED to light up, then after 500ms it should go LOW and led2 goes HIGH and so on. When I run the code LED 1 lights up, after 500ms LED2 goes HIGH but first one doesnt go LOW...
I guess I dont know how to use millis properly so if anyone could help me out it would be so awesome. Here is the void loop which doesnt work.
void loop() {
  unsigned long currentMillis = millis();
  digitalWrite(led1,HIGH);
  if(currentMillis>=500){ digitalWrite(led1,LOW);  digitalWrite(led2,HIGH);}
  if(currentMillis>=1000){ digitalWrite(led2,LOW);  digitalWrite(led3,HIGH);}Â
}
void loop() {
  static unsigned long currentMillis = 0;
  if(currentMillis == 0)
  {
   digitalWrite(led1,HIGH);
   currentMillis = millis();
  }
  if(millis() - currentMillis>=500){ digitalWrite(led1,LOW);  digitalWrite(led2,HIGH);}
  if(millis() - currentMillis>=1000){ digitalWrite(led2,LOW);  digitalWrite(led3,HIGH);}
}
Next can can implement a button reading in the loop. If the button is pressed, set currentMillis to 0 and the sequence starts again.
millis() returns the time in milli seconds since the sketch was started, and resets ~49 days.
The two if statements will be true at 1/2 and 1 second after the sketch has started. >=
You should have one line for each statement.
These will not be true when 49 days has gone by when millis resets then things repeat as before.
The time between the two digitalWrites is very very short, micro seconds, therefore you will not see the flash.
Is this what you wanted?
Everything you need to know about millis
Hello. This is my first post here so dont judge me and help me out if I did anything wrong.
You need a thicker skin, don't read replies that you don't like.