Place to put your Basic demos and examples

Moderator: Mmiscool

User avatar
By Mmiscool
#37026 For this example I used to node mcu boards.

The button that is connected to the gpio 0 is used to control the on board led on the other unit.

There is a bit of a delay between holding down the button and the light turning on or off.


The controller code
You must change the ip address of the receiving unit for your environment.
Code: Select alltimer 5000 [check]
wait

[check]
serialprintln io(pi,0)
if io(pi,0) = 1 then io(po,d4,0)
if io(pi,0) = 0 then io(po,d4,1) 
if io(pi,0) = 1 then wget("172.16.0.112/msg?stat=0")
if io(pi,0) = 0 then wget("172.16.0.112/msg?stat=1")
wait


Receiver unit code:
Code: Select allmemclear
msgbranch [doit]
wait

[doit]
msgget stat s
io(po,d4,s)
msgreturn s
wait
User avatar
By forlotto
#37030 excellent could do some interesting stuff with this ;)
User avatar
By heckler
#37053 That's awesome Mike,
Thanks for sharing the example
These examples REALLY help ALOT as it shows how to use various parts of the ESPBASIC and how to apply the syntax correctly.

could this also be done??

Code: Select all[check]
serialprintln io(pi,0)
if io(pi,0) = 1 then
io(po,d4,0)
wget("172.16.0.112/msg?stat=0")
else
io(po,d4,1) 
wget("172.16.0.112/msg?stat=1")
wait


Probably not as there does not seem to be any sort of "endif" parameter??

Question: How many things can be executed based on an "IF" test?
Only one???

or can we somehow do more than one thing before hitting the "else" part of the test?

thanks for all your work and code examples.

Merry Christmas!
dwight
User avatar
By Mmiscool
#37060 There was actually a bug in the if then command that prevented else from working if the then statement consisted of a single command. I just upload a build that fixes it. I will update the demo to reflect this fix.

Merry Christmas all.