Questions with regards to ESP8266 Basic and hardware interfacing and control via Basic commands

Moderator: Mmiscool

User avatar
By msvb100
#74178 hi Guys
I've been working with ESPBasic for a few days now.
But unfortunately I can not continue.
I want to set a pin high or low and then read it out immediately.
Unfortunately, it does not work.
Valu always stays 0
Also, the attempt to outsource the routine is reported with syntax error.
Would be nice if someone could help me.
Hopefully you can read this text.
He was translated with Google.
Thank you.
Michael S.




Version 1

let valu=99
cls
button "On",[on]
button "Off",[off]
button "Exit",[Exit]
pin= D1


[on]
io(po,pin,1)
valu= io(pi,pin)
print valu
wait


[off]
io(po,pin,0)
valu= io(pi,pin)
print valu
wait

[print]
print valu
wait

[Exit]
wprint |<a href="./edit"> Edit</a>|
end
---------------------------------------------------------------------------------------------------------
Version 2 (Function outsourced....Syntax error)

let valu=99
cls
button "On",[on]
button "Off",[off]
button "Exit",[Exit]
pin= D1

[on]
io(po,pin,1)
valu= io(pi,pin) [print]
print valu
wait

[off]
io(po,pin,0)
valu= io(pi,pin) [print]
print valu
wait

[print]
print valu
wait

[Exit]
wprint |<a href="./edit"> Edit</a>|
end
User avatar
By Luc Volders
#74191 You made several mistakes, which are due (I believe) by not fully understanding the syntax of ESP-Basic.

First:
You should put a wait statement after the main part of the program, before the button routines start.

Second:
Reading the IO pins is done with laststat

So here is your complete edited program:

Code: Select allpin = d6
io(po,pin,0)
cls
button "On",[on]
button "Off",[off]
button "Exit",[Exit]
wait


[on]
io(po,pin,1)
print io(laststat,pin)
wait


[off]
io(po,pin,0)
print io(laststat,pin)
wait

[Exit]
wprint |<a href="./edit"> Edit</a>|
end


Hope this helps.

Luc