Reset Timer with Analog Potentiometer

Hello guys,

I'm would like to reset my timer when analog input is incoming and only keep run my timer when no input is incoming anymore to run sleep function, for example.

here is my timer:

unsigned long timer = 0;
unsigned long countdownTimer = 20000;

void loop () {

  if (millis() > timer + countdownTimer) {

    Serial.println("Timer is ready");
    timer = millis();

    ESP.deepSleep(0);
  }
}

this is how it looks right now. Timer just starts when esp is on and keep running 20 sec.
But I need to set up timer = millis(); when analogRead(A0) input is incoming.

Can someone help me with the function pls?

The only time analogue input is incoming is when you explicitly call analogRead.

I do.
My programm is bit larger, so I decided not to post the whole code here

So, don't call analogRead.

Good luck with that approach

Well, I was just trying to keep things simple.
But I got you. I didn't mean when analogRead is incoming, I meant when it changes. Sry bout that.

So I just need help with function to detect when analogRead value chages. When it does, I will reset the timer, if not, so timer keep running.

  • Read the analog input.
  • Compare the value with the previous value.
  • If they are different:
    • Store the new value in the previous value.
    • Reset the timer.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.