Any way to delay certain parts of code, without delaying the whole thing?

I know the delay milliseconds command is very common, but I'm wondering if there is any way to delay just certain parts of code, without delaying the entire thing, heres a couple examples.

You have 3 sensors (A, B and C), monitoring 3 trigger events (Trigger event A, B, and C), and performing an action upon said trigger event (Trigger event A, B, and C). However once a said event is triggered, such as Event B, you want to completely quit using sensor B for a certain 10 minutes, however you want to keep using sensors A and C, as well as running other parts of the software.

Example 2. You want to blink 2 led's based on a rate of speed adjustable with a potentiometer. With one led it would be simple, write high, then delay for said amount based on potentiometer value, then write low, then delay again....... However how would you make this work with 2 led's and 2 potentiometers? Since the delay command delays the entire set of code, you'd have to somehow give each one their own independent delay so they don't effect each other.

Thanks.

carl1864:
I know the delay milliseconds command is very common, but I'm wondering if there is any way to delay just certain parts of code, without delaying the entire thing, heres a couple examples.

You have 3 sensors (A, B and C), monitoring 3 trigger events (Trigger event A, B, and C), and performing an action upon said trigger event (Trigger event A, B, and C). However once a said event is triggered, such as Event B, you want to completely quit using sensor B for a certain 10 minutes, however you want to keep using sensors A and C, as well as running other parts of the software.

Example 2. You want to blink 2 led's based on a rate of speed adjustable with a potentiometer. With one led it would be simple, write high, then delay for said amount based on potentiometer value, then write low, then delay again....... However how would you make this work with 2 led's and 2 potentiometers? Since the delay command delays the entire set of code, you'd have to somehow give each one their own independent delay so they don't effect each other.

Thanks.

For both examples, take a look at the Bink Without Delay example.

For the first example, you would just need a flag variable that gets set when the event is triggered. After 10 minutes (using the concepts from the Blink Without Delay example) that flag is reset. The even it only run if the flag variable isn't set.

The Blink without Delay example should take care of the second example.

You want to use millis(). You then have to program the tests to determine when you have waited long enough for a particular function.

Var1=millis()
var2=millis()
var3=millis()

each of those variables can be used for an independant delay.