I have my ESP32 working fine with 4 LEDs using the code from the web server tutorial.
For my project I would need to light the LEDs only while holding the push button, as soon as it would be released, the GPIO should return to “LOW”.
In other words: when touching the push botton on the web server page, I expect only a signal LOW-HIGH-LOW to trigger a connected device.
Can anybody help with such a function?
May be that even introducing a “timer” in the basic code, to reset simply the output state of the GPIO after some milliseconds would do the job – any hint how to implement a timer?
Thanks for a soon reply.
Hi.
You can add some Javascript to the web server code. When you click the button, it runs one javascript function, when you release, it runs another function.
You can use the onmouseup and onmousedown events:https://www.w3schools.com/jsref/event_onmouseup.asp
Here you have an application example: when you click the text, it turns one color, and when you release it changes to another color: https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_onmousedown
In this code, we implement a javascript function in a web server project. Take a look to see how to integrate it with your project: https://github.com/RuiSantosdotme/ESP32-Course/blob/master/code/Project_Robot/Project_Robot.ino
I hope this helps.
Regards,
Sara