how to toggle between two subrountines?

Hi, I am very new to Arduino. My questions: How to use "Timer" or "Sensor" to toggle between "Subroutine-A" and "Subroutine-B" easily?

  1. Enable "Subroutine-A"; Disable "Subroutine-B"
  2. After 30 seconds or read Sensor signal, Disable "Subroutine-A"; Enable "Subroutine-B"
  3. Do above again and again for 45 min.

Could somebody give me example codes? (user "Timer" or use "sensor" solution, or both)

Thanks very much in advance.

You don't enable or disable subroutines, you simply call or not call them.

Could you give me some example codes? Thanks!

The blink without delay example provided with the IDE is a useful foundation.

Richard905: My questions: How to use "Timer" or "Sensor" to toggle between "Subroutine-A" and "Subroutine-B" easily?

It sounds like a trivial question, but you don't explain what 'enabling' a subroutine means.

If you design your sketch following the approach demonstrated in the 'blink without delay' example then your two subroutines can each be implemented as a function called repeatedly to execute whichever piece of logic you want 'enabled'. In that case you can simply have a global variable that indicates which of the functions to call, and in loop() you will simply test the value of that variable and call one or other function. To change which function gets called you simply update the global variable, and you can do that whenever you want based on whatever conditions you want - such as based on a timer, or based on the state of an input.