multitasking delay()

Hi, my project controls ttpin on or off. depending on the kind of press, it will turn on or off with or without delay. the loop function monitors what kind of press i will invoke on my + and - buttons. my problem is, if i want another button to overide the ttpin status the delay hinders me to do that.i saw millis() function and chrono.h library but fail to integrate in my code. any suggestions/help? new in coding and arduino. thanks

#include <OneButton.h>
#include <EEPROM.h>

OneButton ttpositive(A4, true);
OneButton ttnegative(A2, true);

int drive = 0;
int drivepin = 9;
int ttpin = 11;
int autodoff = 0;
int autodoffaddress = 0; 

void setup()
{
  pinMode (ttpin, OUTPUT);  
  pinMode (drivepin, INPUT_PULLUP); 

  ttpositive.attachClick(singleclickp); 
  ttpositive.attachDuringLongPress(longclickp); 

  ttnegative.attachClick(singleclickn);
  ttnegative.attachLongPressStop(longclickn);
  
  digitalWrite(ttpin, HIGH);
}


void loop()
{
  drive = digitalRead (drivepin);
  if ( drive == LOW )
  {
    ttnegative.tick();
    ttpositive.tick();
    delay(10);
  }
} // loop


void singleclickp()
{
  if (EEPROM.read(autodoffaddress) == 1)
  {
    digitalWrite(ttpin, LOW);
    delay (10000);
    digitalWrite(ttpin, HIGH);
  }
  else
  {
    digitalWrite(ttpin, LOW);
  }
}

void singleclickn()
{
  if (EEPROM.read(autodoffaddress) == 1)
  {
    digitalWrite(ttpin, LOW);
    delay (10000);
    digitalWrite(ttpin, HIGH);
  }
  else
  {
    digitalWrite(ttpin, LOW);
  }
}

void longclickp()
{
  digitalWrite(ttpin, HIGH);
  delay(1000);
}

void longclickn()
{
  autodoff = EEPROM.read(autodoffaddress);
  if ( autodoff == 0)
  {
    EEPROM.update(autodoffaddress, 1);
  }
  else
  {
    EEPROM.update(autodoffaddress, 0);
  }

  if (EEPROM.read(autodoffaddress) == 1)
  {
    if (digitalRead (ttpin) == LOW)
    {
      delay (10000);
      digitalWrite(ttpin, HIGH);
    }
    else
    {
      delay (10);
    }
  }
}

You saw millis(), now you need to read and experiment using the examples.
Post your code as you progress, and we'll help you tune it up

lastchancename:
You saw millis(), now you need to read and experiment using the examples.

Specifically, you need to read this instructional thread which appears as a "sticky" at the top of this forum. :grinning:

i ended up with my code rewritten and use switch case and its a bit tricky but i manage to get what behavior of the code. thanks