Examples‎ > ‎

Example 1

This example show a simple program permitting to control a relay connected on the pin GPIO16.
A simple Web page is created containing a button to toggle the relay and a led showing the status of the relay.

CODE: example1.bas

''''''''''''''''''''''''''''''''''''''''''''''''''

' ANNEX WI-FI Basic
'example-1
'Simple button controlling a pin toggle function
'can be connected to a relay module
''''''''''''''''''''''''''''''''''''''''''''''''''
relay = 16 ' the relay is connected on the pin GPIO16 (D0 on nodemcu module)
v = 0 ' initial value of the output
onHtmlReload create_page 'defines the page that will be sent at first connection
gosub create_page ' draw the page at the first run
wait ' wait for events

create_page:   ' this is the html page
' clear the screen
cls
html button$("RELAY", toggle_relay)  ' draws a button
html led$(v) ' draws a led
return

toggle_relay:
v = 1 - v  ' invert the status of the output
pin(relay) = v  'set the output pin (the relay)
refresh 'refresh the status of the led
return

Comentarios