SIMON GAME HELP/DELAY WITHOUT DELAY HELP

This is my code:

const byte leds[] = {A3, A2, A1, A0};
const int led = leds[random(0, 4)];

digitalWrite(led, HIGH);

digitalWrite(led, LOW);
Serial.println(led);

I am currently trying to have a "delay" in between when it is high and low. But with my project, I am not allowed the delay function. Also, I have tried adding an if/millis statement, but then there is no "pause" in between the high and low.

Please help, thank you!

You need to make a timestamp variable (make it = millis() to reset it), then add to this timestamp the duration you want, (in millisec of course) and compare the result to millis(). if millis() is still smaller, the program doesn't continue, if millis() become bigger, the part is executed.

you make several stages to this, like:

if(timeStamp+firstDuration > millis()){
first thing to happen
}

if(timeStamp+firstDuration < millis() && timeStamp+secondDuration >= millis()){
second thing to happen
}

if(timeStamp+secondDuration < millis() && timeStamp+thirdDuration >= millis()){
third
}

.
.
.
.

on the last one (or when the user uses a special button), you just reset the timestamp (timeStamp=millis())

that is the theory, nowfor a Simon game, the number of LEDs triggered increase every time, so you will have to find a creative wa to do that... maybe a for loop can do?

So this is what I did:

const byte leds[] = {A3, A2, A1, A0};
const int led = leds[random(0, 4)];
if(timeStamp + firstDuration > millis())
{
digitalWrite(led, HIGH);
}
if(timeStamp + firstDuration < millis() && timeStamp + secondDuration >= millis())
{
digitalWrite(led, LOW);
}

Serial.println(led);

Now the problem with it is what my main issue is; for the Serial.print(led) code that I added. It was for me to see which LED is being chosen after the randomization. The problem is that it does not give each light a break before the next one.

Thank you

Do check out the "Blink without Delay" example of the IDE.