Shop OBEX P1 Docs P2 Docs Learn Events
ELSEIF to turn a light on or off — Parallax Forums

ELSEIF to turn a light on or off

Shadowcasterx4ffcShadowcasterx4ffc Posts: 13
edited 2008-06-20 14:55 in BASIC Stamp
I'm using the DS1302 as the real time chip.
I'm trying to write an ELSEIF which I would like to use to turn a light on and off. I'm writing something which is not correct.
I would like the light to come on at 8am and go off at 9pm



if hour > x then
high 14

elseif hour < x then
low 14

else ?

endif

If anyone can help that would be great
thanks,
chris



▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Greenhouse Project

Post Edited (Shadowcasterx4ffc) : 6/20/2008 2:21:49 PM GMT

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-06-20 14:11
    It sounds like you want the light to be on between 8:00:00 am and 8:59:59 am (inclusive) and off at all other times.
    You didn't describe any of the rest of your program or the hardware involved. Assuming that you read an external
    real time clock at least once a second (into hour)
    if hour = 8 then
       high 14
    else
       low 14
    


    This works because hour will be 8 for one hour and it doesn't matter if you do a high if the pin is already high or
    a low if the pin is already low.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2008-06-20 14:12
    Is this post a reply to your other thread on the DS1302? If so then please reply there and I will remove this message. If not then please edit your message (using the pencil icon above and to the right of the message) and fill in a subject and more details.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • Shadowcasterx4ffcShadowcasterx4ffc Posts: 13
    edited 2008-06-20 14:18
    Mike Green said...
    It sounds like you want the light to be on between 8:00:00 am and 8:59:59 am (inclusive) and off at all other times.
    You didn't describe any of the rest of your program or the hardware involved. Assuming that you read an external
    real time clock at least once a second (into hour)
    if hour = 8 then
       high 14
    else
       low 14
    


    This works because hour will be 8 for one hour and it doesn't matter if you do a high if the pin is already high or
    a low if the pin is already low.
    No, what we need is for the clock to be on between 8am and 9pm, a total of 13 hours.

    Sorry for the confusion, we're using the DS1302 as our timekeeping chip.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Greenhouse Project
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2008-06-20 14:55
    ' if hour is in hex from the RTC, convert it to binary first: hour = hour.nib1*10+hour.nib0
    IF hour > 8 AND hour < 21 THEN HIGH light ELSE LOW light

    Is there some particular reason you want to use ELSEIF?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
Sign In or Register to comment.