Timer or Sensor reading - First event happening

Hey there,

I can't figure out how to code the following:

Either LDR holds given value for 1 sec
or time interval of 35s is exceeded

Whatever happens first, triggers the next step in the code, activating a servo

To summarize, a servo waits at a position until one of these two events kicks in (first), then moves to next position.

Thank you very much!

Hey there,

I am new to arduino but pretty sure interrupts are used to code the following:

-Sensor (LDR) holds given value for 1 sec
-Time interval/delay? of 35s is exceeded

Whatever happens first triggers the next step in the code, change servo position.

I don't know where to start coding, any topics or lessons that cover my question?
Any help highly appreciated!

Thank you very much!
Attenbach

PS:
To summarize, a servo waits at a position until one of these two events kicks in (first), then moves to next position.

MOderator merged two threads.

Please describe what you want to accomplish without going into tech details.

robtillaart:
MOderator merged two threads.

Please describe what you want to accomplish without going into tech details.

After a button has been pressed, an LED should light up after 35 secs except if the button will be pressed again within the 35 sec, then the LED should light up instantly.

Quite simple, still I don't have the coding knowledge. Thank you for your help!

your should make a state machine

int state = 0;    

state == 0 + button pressed                      --> state = 1; start countdown;
state == 1 + countdown > 0 sec;+ button pressed  --> state = 2; led on
state == 1 + countdown == 0                      --> state = 2; led on; reset countdown
state == 2 + button pressed                      --> state = 0; led off;

in code

void loop()
{
  switch(state)
  {
    case 0: 
      if (digitalRead(button) == HIGH)
      {
        countdown = millis();
        state = 1;
      }
      digitalWrite(LED, LOW);
      break;
    case 1: 
      if (digitalRead(button) == HIGH)
      {
        state = 2;
      }
      if (millis() - countdown >= 35000UL)
      {
        state = 2;
      }
      break;
    case 2:
      if (digitalRead(button) == HIGH)
      {
        state = 0;
      }
      digitalWrite(LED, HIGH);
      break;
  }
}