I want to change this code to produce a .5sec ON period and immediately return to OFF, even if the input remains ON for a longer time. In other words, I simply want an input ON message to produce a short relay closure each time.
https://pastebin.com/dWcWDmz3
Thanks for looking
KentM
Hi.
take a look at how to use timers or task schedulers to achieve that.
for example: https://github.com/arkhipenko/TaskScheduler
or simply use millis() to count the elapsed time.
I hope this helps.
Regards,
Sara
Sara, thanks for the reply. The Task Scheduler is far too complex for my paygrade. Your second suggestion contains the keyword. “simply” . The timer is probably the best course of action. I think a better way of describing my needs here is to say that I am trying to make this switch be non-latching rather than latching. In other words , I want the output device to provide a short contact closure each to time the input device sends the “on” payload to the correct topic.
This has also presented me with another thought regarding whether or not I conduct this timing in the output side of the system or the input side? At the present time, I am thinking that the use of a carefully timed duration would be better defined at the output.
Thanks for your help
KentM
Hi.
Yes. I think so too.
If your code is relatively simple, and you don’t mind blocking your code, you can use a delay, which is way easier to implement.
However, adding a timer is better if then you want to add some more tasks without blocking the code.
Let me know if you need further help.
Regards,
Sara