control pins independently without delay()

Didn't my example turn the led on, waited 500ms, then turned it off again?

to use millis(); is like using everything else

what-to-set = what-to-set-it-to;

just like you set the int and long in the top to zero

unsigned long now = 0;

setup()
{
  now = millis();
}

or

setup()
{
  now = millis() + 500;
}

the first will set it to what the current millis is, and the next will set it to the current plus 500

setup()
{
  now + 500 = millis();
}

wont work, because you want to set now + 500 to millis() but there are no now+500 but it don't catch it because it is not a syntax error, because you can do

if (now+500==millis())

and millis is just a number, counting how many milliseconds has passed since it was turned on. Lets say the arduino have been on for 1 second, and you press the button.

void btnDown()
{
  if (eventtime1 != 0) return;
  eventtime1 = millis(); //Set eventtime1 to now
  digitalWrite(event1, HIGH); //turn on event1 pin
}

eventtime1 will then be set to 1000, because 1 second = 1000 millis

the loop will then check the time passed

if(millis() - eventtime1 >= 500)

after 500ms millis() will then be 1500 because it is 500ms since it was powered up

if 1500 minus 1000 is, or bigger than 500 then...

eventtime1 = 0;
digitalWrite(event1, LOW); //turn off event1 pin

I hope this helps you to be able to use millis() :slight_smile: