• Skip to main content
  • Skip to primary sidebar

RNTLab.com

The Ultimate Shortcut to Learn Electronics and Programming with Open Source Hardware and Software

  • Courses
  • Forum
    • Forum
    • Ask Question
  • Shop
  • Account
  • Blog
  • Login

change to momentary operation

Q&A Forum › Category: ESP8266 › change to momentary operation
0 Vote Up Vote Down
Charles Merkel asked 1 year ago

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

3 Answers
0 Vote Up Vote Down
Sara Santos Staff answered 1 year ago

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
 

0 Vote Up Vote Down
Charles Merkel answered 1 year ago

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

0 Vote Up Vote Down
Sara Santos Staff answered 1 year ago

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

Primary Sidebar

Login to Ask or Answer Questions

This Forum is private and it’s only available for members enrolled in our Courses.

Login »

Latest Course Updates

  • [New Edition] Build ESP32-CAM Projects eBook – 2nd Edition April 16, 2025
  • [eBook Updated] Learn ESP32 with Arduino IDE eBook – Version 3.2 April 16, 2025

You must be logged in to view this content.

Contact Support - Refunds - Privacy - Terms - MakerAdvisor.com - Member Login

Copyright © 2013-2025 · RandomNerdTutorials.com · All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.