Solving logical equation in 24 hour format, tricky!
CuriousOne
Posts: 931
Hello.
I'm doing simple Basic Stamp light controller, where user inputs time in 24 hour format (hours & minutes) to turn lights on and off. The problem is, how to do logic with 24 hours?
I have DS1302 and getting time from it, so, code should look like this:
The above code will work, but only in case if ON minutes are less than OFF minutes.
With above provided examples, the LED1 will never come on, since MINUTES can't be less than 18 and greater than 35 at same time.
Any solution to this?
I'm doing simple Basic Stamp light controller, where user inputs time in 24 hour format (hours & minutes) to turn lights on and off. The problem is, how to do logic with 24 hours?
I have DS1302 and getting time from it, so, code should look like this:
USERONHR=8 'On hour USERONMN=35 'On minutes USEROFFHR=19 'Off hour USEROFFMN=18 'Off minutes GOSUB GETTIME 'Query DS1302 and get hours and minutes into variables IF HOURS=>USERONHR AND MINUTES=>USERONMN AND HOURS<=USEROFFHR AND MINUTES<=USEROFFMN THEN HIGH LED1 'main logic code
The above code will work, but only in case if ON minutes are less than OFF minutes.
With above provided examples, the LED1 will never come on, since MINUTES can't be less than 18 and greater than 35 at same time.
Any solution to this?
Comments
Hope this made sense, typing this at 2AM and if it doesn't I'll answer any clarifications after some sleep
-Roger