How to write this idea on Arduino! pls help

i have a question, how do i write correctly this code in Arduino:

if{ analogRead(A0); == HIGH just for 3 second, after that analogRead(A1); == HIGH just for a second}

What i mean "after that" is must be in consecutive with the words before. The last pls change the bolded word.

that's all, thank you for your time to check this! :)

Do you mean that A0 must be HIGH for the duration of 3 seconds and then A1 must be high for a duration of 1 second ?

If so it is hard to advise without knowing the rest of the context.
Also note that analogRead() gives a value from 0 to 1023, and not a simple HIGH or LOW

In general you need to reset the clock (the saved value of millis() ) whenever the tested value is NOT at the desired level. If the clock has not been reset for 3 seconds you have a result. Something like

void loop() {
   if (analogRead(A0) < threshold) {
        startMillis = millis(); // test failed so reset the clock
   if (millis() - startMillis >= 3000) {
       // first test is passed


Hi, What is your application, what is it connected to, inputs and ouputs?

Tom... :)

another question does "just for three seconds " mean that:

1) the signal must be above the thresholds lets say between 2.9 and 3.1 seconds but no longer?

2) the signal must be above the thresholds at least 3.0 seconds ...

(same for the 1 seconds question of course)

For TomGeorge -for reading the blink led -it's connected to a photoresistor sensor -input: photoresistor -output: -(just reading the value of sensor at serial monitor)

For robtillaart the first option please!

sorry for my incomplete information ::) :)

A simple blocking implementation fo a function

boolean analogAboveThreshold(int pin, unsigned long millisec, int threshold)
  unsigned long start = millis();
  while (analogRead(pin) >= threshold); // blocking !!
  unsigned long duration = millis() - start;

  return ( abs(duration - millisec) <= 100 ); 

if (analogAboveThreshold(A0, 3000, 500) )
   // yes we have ~3 seconds high