8

Just curious, but have you checked CPU usage ? Programs that run in a while loop can be terribly inefficient and taxing. Here you are just probing a sensor, this does not look like a computationally-intensive task but it's still overkill. Seems to me that a timer would be preferable. Sampling values from your sensors at regular intervals, even every few ...


6

If I understand what you are trying to do, I think you can (1) remember the prior state, (2) print only on changes, and (3) select the message to print based on the new state. def water_level(): messages = { False: "The system has water", True: "The system is dry and needs water", } previous = None while ...


4

I agree with @Anonymous that you should not loop continuously like that, or you'll waste energy and CPU time continuously checking the values. To solve this you can just sleep, wake up every minute, check the state and go back to sleep. Another more code-style related observation is that you don't need to nest while loops like that, but only keep track of ...


Only top voted, non community-wiki answers of a minimum length are eligible