Place to put your Basic demos and examples

Moderator: Mmiscool

User avatar
By heckler
#63118 Hi dziloo,

Did you load it on a module and try and run it? If so what was the error message? Then if you look at the line number in question you will find a clue to the problem.
I got it working by changing just two lines (adding commas... which is a major difference between 2.x and 3.x [commas])

below the code now works for me.
see if you can find the two lines 32 and 41.
Note: a good way to find the numbered lines is to look at the code in the "Debug" tab, then go back to the edit window to correct it. (not sure if you can edit in the debug window)

hope this helps
dwight

Code: Select all'                                        BIG COLOURED TOGGLE BUTTON
let ledpin = 13 ' Sonoff LED pin, change to suit for others
let relaypin = 12 ' Sonoff Relay pin, change to suit for others
let ledlogic = 1    'Default led pin off state (allows configuring led pin for active high or active low operation)
let relaylogic = 0  'Default relay pin off state (allows configuring relay pin for active high or active low operation)
io(po,ledpin,ledlogic)
io(po,relaypin,relaylogic)

[HOME]
cls
wprint "<BR><BR><BR><BR><BR><BR>"
wprint |<!DOCTYPE html>|
wprint |<html>|
wprint |<head>|
wprint |<style>|
wprint | .button, input[type="button"], input[type="submit"] { |
wprint |  display: inline-block;|
wprint |  padding: 15px 25px;|
wprint |  font-size: 32px;|
wprint |  cursor: pointer;|
wprint |  text-align: center;|
wprint |  color: #fff;|
if io(laststat,relaypin)=0 then wprint |background-color: #4CAF50;| else wprint |background-color: #f44336; /* Red */|
wprint |  border: 2px solid black;|
wprint |  border-radius: 15px;|
'wprint |  box-shadow: 0 9px #999;|
wprint |}|
wprint |</style>|
wprint |</head>|
wprint |<body>|
wprint |<div style="text-align: center;">|
if io(laststat,relaypin) = 0 then button "ON",[TOGGLE] else button "OFF",[TOGGLE]
wprint |</div>|
wprint |</body>|
wprint |</html>|
wait

[TOGGLE]
if io(laststat,relaypin) = 0 then io(po,relaypin,1) else io(po,relaypin,0)
if io(laststat,ledpin) = 0 then io(po,ledpin,1) else io(po,ledpin,0)
goto [HOME]

' - See more at: http://www.esp8266.com/viewtopic.php?f=40&t=10130#sthash.0ZqbGHMh.dpuf
User avatar
By Electroguard
#63129 Try this...
Code: Select allmemclear
let ledpin = 13 ' Sonoff LED pin, change to suit for others
let relaypin = 12 ' Sonoff Relay pin, change to suit for others
let ledlogic = 1    'Default led pin off state (allows configuring led pin for active high or active low operation)
let relaylogic = 0  'Default relay pin off state (allows configuring relay pin for active high or active low operation)
io(po,ledpin,ledlogic)
io(po,relaypin,relaylogic)

[HOME]
cls
wprint "<BR><BR><BR><BR><BR><BR>"
tmp = "text-align:center;padding:3px;border-radius:15px;border-width:2px solid black;font-size:48px;color: #fff;"
if io(laststat,relaypin) = 0 then button "ON", [TOGGLE] else button "OFF", [TOGGLE]
if io(laststat,relaypin)=0 then tmp = tmp & "background-color: #4CAF50;" else tmp = tmp & "background-color: #f44336;"
cssid htmlid(), tmp
wait

[TOGGLE]
if io(laststat,relaypin) = 0 then io(po,relaypin,1) else io(po,relaypin,0)
if io(laststat,ledpin) = 0 then io(po,ledpin,1) else io(po,ledpin,0)
goto [HOME]
User avatar
By heckler
#63161 Nice Electroguard!

Yours is even better. It actually does a BIG button.

dwight

PS. To all the espBASIC users. It is easy to test out most bits of code posted here (at least to see the web page created) by just powering up a nodemcu module (or other module with 2-4 meg, so all the gui features work, like debug, etc) and copy/paste into your test module and run it. You usually can at least test the web portion without doing any external module wiring. Which is what I just did to see the BIG button!
User avatar
By Electroguard
#63177
Yours is even better. It actually does a BIG button.

Well dziloo asked if it could be fixed, and I was the original poster who offered the BIG COLOURED TOGGLE BUTTON - which obviously worked on V2, but now evidently just displays an ordinary unstyled button even after comma's have been added for correct button syntax.
So I ripped out all the old webby 'div' styling methods and applied the appropriate styles using V3's new cssid htmlid() to give him the same result as original (with a lot less code). If it had been as easy to do back in V2 days I doubt I would have even bothered posting the original article, but it felt like quite an accomplishment at the time.