Sparkfun Clock module time comparisson?
qxotic
Posts: 47
Hello,
For my project the clock is working fine. I am using the Real Time Clock Module from Spark Fun which I believe uses the DS1307. I am working with just the hours in my problem. It displays properly when you tell it to display Hex2 clock(2) as a decimal number on the screen.
The problem is, since the clock keeps the number in hex I am not sure how to go about using it in an IF statement for evaluation.
I want to say If clock(2) > 7 and clock(2) <20 Then......
The problem is because it is in hex I am having to use some very odd numbers to ballpark it at the moment... such as 5 and 34 instead of 7 and 20. (7 am and 8 pm).
How do I change clock(2) to a decimal for my IF statement evaluation?
Thank you,
Daniel
For my project the clock is working fine. I am using the Real Time Clock Module from Spark Fun which I believe uses the DS1307. I am working with just the hours in my problem. It displays properly when you tell it to display Hex2 clock(2) as a decimal number on the screen.
The problem is, since the clock keeps the number in hex I am not sure how to go about using it in an IF statement for evaluation.
I want to say If clock(2) > 7 and clock(2) <20 Then......
The problem is because it is in hex I am having to use some very odd numbers to ballpark it at the moment... such as 5 and 34 instead of 7 and 20. (7 am and 8 pm).
How do I change clock(2) to a decimal for my IF statement evaluation?
Thank you,
Daniel
Comments
Currently I have
ELSEIF clock(2)>5 AND clock(2)<34 THEN
GOSUB ValidCode 'code to compare hour of day.. I want the code to only be valid between 7am and 10 pm.. using 24hr clock
DEBUG HEX2 clock(2), ":", HEX2 clock(1), ":", HEX2 clock(0), CR 'this displays the correct time.
I have two ideas to try from what I read...
1st..
ELSEIF clock(2)>$06 AND clock(2)<$22 THEN
2nd idea...have to add one variable called HrsDec
HrsDec = (clock(2).NIB1 * 10) + clock(2).NIB0
ELSEIF HrsDec > 6 AND HrsDec < 22 THEN
I will try this on the stamp in operation in the next day or so... would both of these work? If not can you please elaborate as to why?
Thank you,
Daniel
Thanks to all,
Daniel