Answer the question
In order to leave comments, you need to log in
Answer the question
In order to leave comments, you need to log in
While one code is running, the other is not running.
If you need to perform several tasks at the same time - use JS
I do not guarantee that the solution is optimal, but you can try this:
By interrupt, subscribe to change the value on the port
https://www.arduino.cc/reference/en/language/funct...
In the handler function, remember the start time. When you call again, calculate the difference. The pseudocode is something like this:
unsigned long time = 0;
const int signalType = HIGH;
int signalDuration = 0;
void onSignal()
{
if (signalDuration)
return;
if (digitalRead(inPin) == signalType)
{
time = micros();
}
else
{
signalDuration = micros() - time;
}
}
void loop() {
//...
if (needToCalculateDuration)
{
needToCalculateDuration = 0;
signalDuration = 0;
//attachInterrupt(...)
}
//...
if (signalDuration)
{
//detachInterrupt
doSmthWithDuration(signalDuration)
}
//...
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question