IF Statement using a Bolean expression
Mt Shasta Forest
Posts: 4
Greetings,
I have been banging my head on trying to read the clock so I can have a day and night mode for reading my solar panel and battery bank voltages.
I have the AD converter up and running now, reading the voltages every 15 minutes.· But want to read them every 15 minutes or 30 minutes from 6am to 9pm then once every hour during the night.
I used the DEMO Clock program to set the clock in the 24 hr format.
What I would like to do is something like this ....
GOSUB Get_Time
IF hrs =>21 AND hrs <6·THEN GOTO Hourly
GOTO Quarterly
It goes to my Hourly routine no mater the time.
With the following I am able to get some things to work but not able to get the program to run hourly when the time is past 9pm
What I wrote:
GOSUB Get_Time
If hrs <6 then GOTO Hourly1· ... ( this just is a Debug "time recording 00:00 to 05:59") and works fine
If hrs =>21 THEN GOTO Hourly2 ... ( this just is a Debug "time recording 21:00 to 24:00") will goto hourly2 when clock is set at 19:00 hrs...
GOTO Quarterly ...
when i remove the "IF hrs =>21 THEN GOTO Hourly2 ...
and the time is say 10:00 ( 24 hr clock ) it goes to the quarterly routine with no problem
I am new to this and may be just missing something.
Goal is to have a data logger on the remove solar system so I will be able to download a few weeks of info at one time.
Thanks
Rick
·
I have been banging my head on trying to read the clock so I can have a day and night mode for reading my solar panel and battery bank voltages.
I have the AD converter up and running now, reading the voltages every 15 minutes.· But want to read them every 15 minutes or 30 minutes from 6am to 9pm then once every hour during the night.
I used the DEMO Clock program to set the clock in the 24 hr format.
What I would like to do is something like this ....
GOSUB Get_Time
IF hrs =>21 AND hrs <6·THEN GOTO Hourly
GOTO Quarterly
It goes to my Hourly routine no mater the time.
With the following I am able to get some things to work but not able to get the program to run hourly when the time is past 9pm
What I wrote:
GOSUB Get_Time
If hrs <6 then GOTO Hourly1· ... ( this just is a Debug "time recording 00:00 to 05:59") and works fine
If hrs =>21 THEN GOTO Hourly2 ... ( this just is a Debug "time recording 21:00 to 24:00") will goto hourly2 when clock is set at 19:00 hrs...
GOTO Quarterly ...
when i remove the "IF hrs =>21 THEN GOTO Hourly2 ...
and the time is say 10:00 ( 24 hr clock ) it goes to the quarterly routine with no problem
I am new to this and may be just missing something.
Goal is to have a data logger on the remove solar system so I will be able to download a few weeks of info at one time.
Thanks
Rick
·
Comments
If you’re using the code I think you are then you should be comparing to HEX values such as $06 and $21. By comparing with decimal values you’re not going to be getting the comparison you expect. On top of that if you’re comparing right after the Get_Time routine there are bits set for the AM/PM flag and 12/24 Mode at certain times which will make the resultant numbers incorrect. You need to strip (and save) the extra information into the flags before that point. This is covered in the DS1302 Demo Code. I hope this helps. Take care.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
this topic
"
GOSUB Get_Time
IF hrs =>21 AND hrs <6·THEN GOTO Hourly
GOTO Quarterly
he states that it will do hourly, but not the quarter hour
can you have two goto's that follow one another
or should he have an "else" in there
such as
GOSUB GET_TIME
if hours =>21 and hrs <6 then Goto hourly
else goto Quarterly
or is the problem simply the use of the number 21 and 6 ??
bob g
Your thoughts about ELSE would hold true if for example he had used GOSUB instead of GOTO.
Jeff T.
As a note the conditionals won’t work as expected due to the difference in the value of a hex value as opposed to a decimal value. Take care.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
Although it is working as you would expect it is not working correctly, the reason being we are not passing the values in the correct format or the condition is not formatted correctly.
I'm sorry if this is a little off topic I wanted to help bob understand how Rick's code used GOTO's to conditionaly branch to two seperate routines and that the use of the GOTO's was not the problem here.
Jeff T.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Truly Understand the Fundamentals and the Path will be so much easier...
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support