Remember button state


#1

HEY GUYS
im trying to devlop a way to remember button state and have it stay constant even if i switch screens, any help please. In my example im trying to have LED on for exapmple and have the button stay green if its on or turn the button off its its off based on this function on my particle photon.

int  FrontLights(String ledCommand) {

String convertedCommand = ledCommand.toUpperCase();

if (convertedCommand == “ON FRONT”) {
digitalWrite(frontlight, HIGH);
return (1);
} else if (convertedCommand == “OFF FRONT”) {
digitalWrite(frontlight, LOW);
return (0);
}
else {
return (-1);
}
}

So when the “ON FRONT” command is called it would turn the front led on and turn the button green. Same for “OFF FRONT” turn the led off and turn the button green. My problem is that when i go to another screen and come back it dosen’t keep it in that state, but instead resets the button colors even though the physical state of the button remains on or off.

I want to be able to remember tthe state even if i go to another screen and return, any help please.


#2

Hi @GYGTGR,

What does this extension do?
Can I find it? … Is it free or paid?


#3

use TinyDB to store the state
TinyDB tutorial by Stephen

Taifun


Trying to push the limits! Snippets, Tutorials and Extensions from Pura Vida Apps by Taifun.


#4

Thanks for your reply,
How would i store the value wit TinyDB


#5

it does not look like you did the previously mentioned tutorial, did you?
Taifun