Shop OBEX P1 Docs P2 Docs Learn Events
IF Statement using a Bolean expression — Parallax Forums

IF Statement using a Bolean expression

Mt Shasta ForestMt Shasta Forest Posts: 4
edited 2007-05-16 19:46 in BASIC Stamp
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


·

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2007-05-16 15:00
    Rick,

    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
  • mobile_bobmobile_bob Posts: 50
    edited 2007-05-16 15:49
    i am a newbie as well so i am reposting part of the code so as to ask a question and learn from

    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
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2007-05-16 16:20
    Hi bob, Rick's conditional statement is fine, he is looking for one of two conditions, if the first is true the GOTO skips the second and performs the "hourly" routine. If the first condition is false by default it will operate the second GOTO "quarterly" condition.

    Your thoughts about ELSE would hold true if for example he had used GOSUB instead of GOTO.

    Jeff T.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2007-05-16 17:12
    Jeff,

    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
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2007-05-16 18:29
    Thanks Chris I did realise that, I was pointing out to bob the valid use of the GOTO statements. Which in actual fact are working as you would expect.

    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.
  • Tom WalkerTom Walker Posts: 509
    edited 2007-05-16 18:45
    Can hrs actually be >=21 AND at the same time <6?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Truly Understand the Fundamentals and the Path will be so much easier...
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2007-05-16 19:46
    I would say OR. Take care.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
Sign In or Register to comment.