• 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

Web server with push buttons

Q&A Forum › Category: ESP32 › Web server with push buttons
0 Vote Up Vote Down
dieter.wingel asked 4 years ago

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.

1 Answers
0 Vote Up Vote Down
Sara Santos Staff answered 4 years ago

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

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

  • [eBook Updated] SMART HOME with RPi, ESP32, and ESP8266 (version 1.2) March 8, 2023
  • [eBook Updated] ESP32-CAM Projects (version 1.3) January 7, 2023

You must be logged in to view this content.

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

Copyright © 2013-2023 · 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.