I'm trying to write web server code. However, I am having trouble with part of it.
Currently, to get it to save a bool variable I have it use a pin, as when I ran the code without it, after the page refreshes it resets the variable to its original value.
How do I get it to save the variable in this code without it using the pin?
digitalWrite (equalPin, server.arg("equal").toInt());
char equalText[80];
if(equalState) {
strcpy(equalText, "priority is equal. <a href=\"/?equal=0\">Deactivate</a>");
equalState = false;
} else {
strcpy(equalText, "priority is not equal. <a href=\"/?equal=1\">Activate</a>");
equalState = true;
}
equalState = digitalRead(equalPin);
I also have several over copies of this for different pages but if I change 1 of them they all change and reset after 10 seconds.
The code follows the example on this site.
1 Answer 1
same code snippet without using pin
char equalText[80];
if (equalState){
strcpy(equalText, "priority is equal. <a href=\"/?equal=0\">Deactivate</a>");
equalState = false;
}
else {
strcpy(equalText, "priority is not equal. <a href=\"/?equal=1\">Activate</a>");
equalState = true;
}
equalState = server.arg("equal").toInt();
but it does not make much sense to set the value if you already switched the state based on it's previous value
-
That seems to have worked it just doesnt auto refresh the page anymore but thats fine.Apple– Apple2018年04月22日 11:44:54 +00:00Commented Apr 22, 2018 at 11:44
if
andelse
you change it and then you revert to the value beforeif
andelse
. perhaps learn coding first.