Alternate between two procedures

Hello. I've created an app which gets data from arduino and confronts it with a max value and a min value (that I already set). When the value is between the two limits, there's a procedure which enables the "normal procedure". However, when the value is outside those limits, it will trigger an alarm procedure. The problem is that once the alarm procedure goes off, the normal procedure doesn't go away. How can I fix this? Procedures are at the end of the sketch.

It's hard to tell without seeing the code running on the other device. Can you also post the C code running on your arduino?

I now scrapped the part I've talked about in this post. However I could still rewrite it. Basically the app will send 3 values that will be processed by arduino through the switch function. In particular, when I open a sensor screen, the "normal procedure" will turn on the green led, as to mean that everything is okay. But when something is wrong, the "alarm procedure" will instead turn on the red led turning off and on. But the green led won't go away, so I don't know how to "end" the previous procedure. Here's the code, I didn't write this part I just told you so hopefully you could help me with it.

bluetooth_automation.txt (9.6 KB)