LED


This command was created to avoid having to mess with GPIO pins and TIMER commands. Its secondary purpose is to easily demonstrate the output of more complex commands. In the first row of the Setup/Peripherals menu, the LED wiring can be configured. The built-in LED of the WeMos D1 mini module is D4-Vcc, which is the default setting. If WiFi is checked (default), it blinks quickly in AccessPoint mode when someone is connected. In client mode, it blinks slowly if it successfully connects to the router. It flashes during boot. It lights up while formatting the storage, and you have to wait until it goes out. The GPIO command issued to the LED pin stops the WiFi status indication.


LED@
Sends the LED status to STDOUT. The @ can be used after every LED command.

LED(ON)
The LED is on.

LED(OFF)
The LED is off.

LED(TOGGLE)@
The LED toggles its state.

LED(EMBER)
The LED glows.

LED(FLASH)
The LED lights up for 250ms.

LED(FLASHI)
The LED state changes for 250ms.

LED(3000)
The LED lights up for 3000ms.

LED(BLINK1)
The LED blinks.

LED(BLINK2)
The LED blinks slowly.

LED(BLINK3)
The LED blinks quickly.

LED(BLINK4)
The LED blinks slowly, inverse.

LED(BLINK5)
The LED blinks quickly, inverse.

LED(BLINK6)
The LED blinks very quickly.

LED(WIFI)
The LED shows the WiFi status.



Examples


WebSocket example, the "button" element toggles the LED. The WebSocket connection is created in the script. <!DOCTYPE html> <html> <body> <H1>LED CONTROL</H1><br> <button type="button" onclick="websocket.send('LED(TOGGLE)@')">TOGGLE</button> <br> <H2 id="wsdata"></H2> <script> var port = ""; if (window.location.port) {port = ":" + window.location.port;} var gateway = "ws://" + window.location.hostname + port + "/ws"; var websocket = new WebSocket(gateway); websocket.onopen = onOpen; websocket.onclose = onClose; websocket.onmessage = onMessage; window.onunload = window.onbeforeunload = onExit; function onOpen() { //commands if open this page websocket.send( 'LED@' ); } function onExit() { //commands if close this page } function onClose() { //commands if interrupt connection alert("Interrupt connection!"); } function onMessage(event) { //commands if message received document.getElementById("wsdata").innerHTML = event.data; } </script> </body> </html>
When opening the webpage, the LED turns on, and when closing it, the LED shows the WiFi connection status. The WebSocket connection is handled by tools.js <html> <body> <H2>Open Page: The LED is on.</H2> <H2>Close Page: The LED shows the WiFi state.</H2> <script type="text/javascript" src="tools.js"></script> <script> startWS(0); function onOpen() { sendWS('LED(ON)'); } function onExit() { sendWS('LED(WIFI)'); } </script> </body> </html>