Place to put your Basic demos and examples

Moderator: Mmiscool

User avatar
By Electroguard
#45602 I haven't got round to trying this yet, but it might be what you're after (saving a pin-state variable to persistent memory so it can be read back again after power-on or reboot).


READ:

The read command allows you to retrieve information persistently stored in the flash memory of the ESP8266 module.

read {string or var for name of data element} {Var to place contents of data element into}

WRITE:

The write command allows you to persistently store a data element in flash memory.

write {string or var for name of data element} {Var or sting to write to data element}
User avatar
By forlotto
#45619 yes so anywhere in your code you set pin (whateverpin) to a value of zero you can setup pin1reg lets say as ON.

Code: Select all
pin1reg = 1

button "Pin1 ON" [Do1]
button "Read Pin1" [readit]
wait

[Do1]
cls
po 1 0
pin1reg = 0
wait

[readit]
cls
if pin1reg = 0 then print "Pin 1 is ON" else print "Pin1 is OFF"
wait


This is similar to what I did before LETSTAT was introduced... Took a little convincing but finally I think mmiscool understood the number of uses something like this could actually have when at first he was rather reluctant now it is a lot easier pins are formally tracked for you you just ask for the value and then print it with LETSTAT errr it may be LetStat IDK read the documentation on that one things are CASE SenSitiVe.

Note this is just and example there are specific pins you are allowed to use for ON/OFF function you may want to keep this in mind to know what pins refer to the guide in my signature.

Enjoy,

-forlotto
Last edited by forlotto on Sun Apr 17, 2016 11:03 am, edited 2 times in total.
User avatar
By forlotto
#45641 Note this is just and example there are specific pins you are allowed to use for ON/OFF function you may want to keep this in mind to know what pins refer to the guide in my signature.

Errr you bet it does because at a powercycle the register is set to 1 or off ...

However if you want the device to come on after a power cycle you can too just set it in your program in the beginning but anywhere you set a 0 or a 1 for a pin just be sure to follow it with code that sets your register it is a home made register really you could name it TV or Porchlight or whatever I personally like to keep it pin1reg pin2reg pin3reg etc... This way I know what pin it is representing.

When ever you print you read your status you can have it print what it is like so...

Lets imagine pin1 was a Soundbar you were trying to turn ON or OFF
Lets imagine you were using pin2 for your TV to turn ON or OFF

You could label your button accordingly and print accordingly make it your own!
Declare this at the beginning of your code because they start off in the off position which is 1 for my hardware.
pin1reg = 1
pin2reg = 1
If you wanted your stuff to turn on after a reset here you would set that like so. If you don't want them to come on automatically don't add the code below.
po 1 0
pin1reg = 0
po 2 0
pin2reg = 0
Notice how any time you use po to turn on / off in your code you will want your code to also set the same thing for your register which for me is pin1reg pin2reg etc... You don't have to use them names pin1reg for instance you could name soundbarreg and pin2reg could be tvreg it is entirely up to you.

Now lets declare our buttons the next bit of code does this.
cls -start off with clearing the screen buffer if you do not you will windup with more buttons each time you push one
Button "Sound Bar ON" {soundON]
Button "Sound Bar OFF" [soundOFF]
wprint "<br>" basically we just have the next set of buttons start on the next line.
Button "TV ON" [TVON]
Button "TV OFF" [TVOFF]
wprint "<br>"
Button "STATUS" [Status]
wait
Above notice the [braces} this is the subroutine that we go to when we have that button pushed.
Below are the subroutines more or less.

[soundON]
po 1 0 turning pin1 to ON this may actually be 1 depending on your hardware setup this may be actually OFF instead.
pin1reg = 0 Still tracking the pin status when ever you turn on or off let it be known to your register as well in your code
wait

[soundOFF] when Soundbar OFF is pushed it will turn pin 1 off with the subroutine and track it again like below.
po 1 1
pin1reg = 1
wait

[TVON]
po 2 0
pin2reg = 0
wait

[TVOFF]
po 2 1
pin2reg = 1

[Status] This subroutine basically will check your pin1reg and pin2reg and then report accordingly.
cls clear screen buffer otherwise it will keep appending prints and overflow the screen buffer
print "Current Status <br>"
if pin1reg = 0 then print "Soundbar is ON <br>" else print "Soundbar is OFF <br>"
if pin2reg = 0 then print "TV is ON <br>" else print "TV is OFF <br>"
print "End of status report"
wait

This would be all of the code you will have to remove the explanations and make it your own but it should work !


This should be enough info to get anyone started making there own pin tracker...

However it is easier to do with LETSTAT and takes less code etc.. I would personally suggest that route instead. but the example and the explanations gives people an understanding of what code is actually doing and how to work with it and when to use certain things remember things are case sensitive if you had a routine named [ABC] your button must go to [ABC] not [abc] or [Abc] as these are two different routines same goes for your register if pin2reg is your reg and later in your code you typed Pin2reg = 0 for instance it would not change your register remember treat your code like linux terminal not windows command line and you will be OK ....

GOOD LUCK TO ALL!