tinyDB to remember button state part 2

I am using the app to control an Arduino that controls relays to do various tasks. The app, after picking the proper bluetooth signal, remembers it for later use, and on exit, completely closes the app and disconnects from bluetooth. The disconnect was needed so that another device would be able to connect. The Arduino and relays stay in whatever state they are in until receiving instructions, via bluetooth, to do something else.

For the three buttons, that toggle on/off, there is a text box to indicate if the switch is on or off with text stored in a tinyDB.

The two buttons, that are simple toggle switches, work correctly with the correct label in the text box, in use and on app open.

First problem is if those switches are left "ON" the next time you open the app it shows ON which is correct. To get it to turn OFF you have to tap button twice. If left OFF when you open app one tap turns it on.

Second main problem, if the door is left locked when the app is started the text shows locked as soon is bluetooth shows connected the text changes to "unlocked" while the lock stays locked.

Also attaching aia file
ControlPanel_2_1_1.aia (2.2 MB)

I think the problem stems from having two different ways to store the 'truth' of your states,

  • the global variables that you increment when you flip state, and
  • the TinyDB contents that you flip.

I would drop the global variables, and use only the TinyDB contents.

Thanks, I simplified the button toggle and got rid of the global variables and all works like it should. :grin:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.