Thank you so much,Let me just clarify that there should only be one count-down, and they are all else/if statements based on the decision tree below:You have three countdown timers. Each for the same 4 hours.
Is there water in the tank?
If no wait four hours and restart loop
if yes, does the soil need watering?
If no wait four hours and restart loop
if yes water, then wait four hours and restart loop.So let me check;Maybe it is doing what you asked. But what you asked is not what you actually wanted...
What I want is that it checks each of those and then counts down 4 hours until it checks again. How would I change the code to make that happen?
Again, thank you so much for this
Code:
if tank contains water and soil needs watering:water itexit
As for your code, judging by lines 289 - 303
Code:
for seconds_remaining in range(total_seconds, 0, -1): hours = seconds_remaining // 3600 minutes = (seconds_remaining % 3600) // 60 seconds = seconds_remaining % 60 lcd.move_to(0,3) lcd.putstr("See you in:\n") lcd.move_to(12,3) lcd.putstr("%02d\n" % hours,) lcd.move_to(14,3) lcd.putstr(":%02d\n" % minutes) lcd.move_to(17,3) lcd.putstr(":%02d" % seconds) time.sleep(1) control_led(False) # Turn off LED time.sleep(4 * 60 * 60)
A couple of other points:
- On line 126 you "Calculate total seconds for 4 hours". On several other lines (e.g. line 303) you calculate it again rather than using the stored value.
- Your four (eight) hour intervals will increase from four hours over time. You're using a set interval and not accounting for the time it takes to execute the code prior to entering the sleep.
- As you're using the for loop I included above several times it will simplfy maintaining your code significantly if you move it into a function.
- Lines 305 - 309 will never be executed. They need to be moved to before the main loop.
In case you need help with cron: Cron – A Beginner's Guide
[/shameless self promotion]
Edited to strikeout wrong information and incorrect suggestions
Statistics: Posted by thagrol — Fri Aug 02, 2024 4:43 pm