Timing Problem

Hi
My aim is on pressing a switch to turn on a relay on an Arduino output for a set length of time and then have the output turn off

I need to be able to
Vary the on time between 0.1 seconds and 10 seconds in steps of 0.1
Set a variable for the on time with perhaps two up/down switches one for seconds and
one for 1/10ths of a second
Show the length of the on time variable with an LCD

I know how to
wire up the relay
wire up the LCD and write its code to show the value set in a variable
change the value of the variable with the two up/down switches

Where I get stuck is I assume I need an ISR to control the timing and I dont know how to do that

Can someone help please

Don

You don't need an ISR for such a simple program, see BlinkWithoutDelay.

What you have to do is

  • set a flag when the relay should be turned on.
  • at the same time turn the relay on, and remember the current time
  • if flag set and interval exceeded, turn relay and flag off

If this looks too complicated to you, try the task macros:

void monoFlop() {
taskBegin();
 taskWaitFor(relayFlag);
 relayFlag = false;
 digitalWrite(relayPin, ON);
 taskDelay(yourInterval);
 digitalWrite(relayPin, OFF);
taskEnd();
}

Then call monoFlop() from loop(), and set relayFlag when the relay should be turned on.

DrDiettrich:
You don't need an ISR for such a simple program, see BlinkWithoutDelay.

What you have to do is

  • set a flag when the relay should be turned on.
  • at the same time turn the relay on, and remember the current time
  • if flag set and interval exceeded, turn relay and flag off

If this looks too complicated to you, try the task macros:

void monoFlop() {

taskBegin();
taskWaitFor(relayFlag);
relayFlag = false;
digitalWrite(relayPin, ON);
taskDelay(yourInterval);
digitalWrite(relayPin, OFF);
taskEnd();
}


Then call monoFlop() from loop(), and set relayFlag when the relay should be turned on.

Thats great DrDiettrich
thank you for your advice

Don