I'm trying to add a delay between an Input and output trigger and it's not working.
What I want to do is, when the input trigger receives a pulse, wait a small moment, and then trigger the output trigger.
I would like the "timerInterruptHandler" function to be called after the 10ms but it's always in sync with no delay.
Here's the sample code I'm using,
Here's a view of the scope, Input #1(yellow) is Pin 23(input trigger) and Input #2(Purple) is hooked to Pin 21(output trigger). You can see they are triggered at same time, without the delay.
What I want to do is, when the input trigger receives a pulse, wait a small moment, and then trigger the output trigger.
I would like the "timerInterruptHandler" function to be called after the 10ms but it's always in sync with no delay.
Here's the sample code I'm using,
Code:
#include <TimerThree.h>
void setup() {
pinMode(23, INPUT_PULLUP); //Input Trigger
pinMode(21, OUTPUT); //Output Trigger
attachInterrupt(digitalPinToInterrupt(23), inputInterruptHandler, RISING);
Timer3.attachInterrupt(timerInterruptHandler);
}
void inputInterruptHandler() {
Timer3.initialize(10000); // Wait 10ms before changing output
}
void timerInterruptHandler() { // Issue: This function should be called after the delay, but is called immediately
digitalWrite(21, HIGH);
delayMicroseconds(100);
digitalWrite(21, LOW);
Timer3.stop();
}
void loop() {
}
Here's a view of the scope, Input #1(yellow) is Pin 23(input trigger) and Input #2(Purple) is hooked to Pin 21(output trigger). You can see they are triggered at same time, without the delay.