Shop OBEX P1 Docs P2 Docs Learn Events
Please help for the newest of the newer than newbies — Parallax Forums

Please help for the newest of the newer than newbies

Hard TimesHard Times Posts: 7
edited 2004-08-02 20:40 in BASIC Stamp
··I'm an old tech who·just got started in BS2 stamping due to a·problem I am·faced with solving. I have read and done the first 10 or so activitys in the "What's a Microcontroller"· book. I do plan on completing this tutorial--- after my problem is solved.· After glancing through the book, I can only satisify part of the solution with the needed code. I'm looking for suggestions to get·beyond what I've learned so far. Here goes.
I only have one "input", a SPST switch, and three relays to drive.·When the SPST·switch goes from low to high (for any lenght of time greater than 20 msec), I need to do·six things:

·1.) Energize·one of the·relays (call it·"X"), via a driver, for 3 seconds, then denergize "X"

·2.) Remember that this on/off ·event has occured

·3.)·Do nothing·further until SPST switch goes low again (for any lenght of time greater than 20 msec),··· then·wait··(for any lenght of time)·for SPST input to go high again.

·4.)This sequence will repeat until relay "X" has been driven·closed 3 times.

·5.) On the fourth to sixth SPST·low to high activations, relay "Y" will energize just like 1.) 2.) and 3.) as··· above.·····

·6.) On the seventh to ninth SPST activations, relay "Z" will also repeat 1.) 2.) and 3.) as above.
····· Thats all, job is done.

·I have hacked out this code so far that works well for the "3 sec on" and the ·"wait until" ·part of the job.· I don't see any examples in my book·of the count and remember parts that I need.· My very rough·virgin code so far·looks like·this:

···· DO
········ IF IN3=1 THEN·· ; IN3 is SPST
·········· HIGH 14········· ; Pin 14 is driver for relay"X"
·········· PAUSE 3000
·········· LOW 14
········ DO
············ LOOP UNTIL IN3 =0
········ ENDIF
···· LOOP
·
Of course I don't have relay "Y" and "Z" coded yet, because I can't·figure out how·the "remember" and "count to three" ·stuff works yet.·
·Please help to steer me in the right direction on getting the code worked out., I'm getting frustrated·with myself for not seeing the obvious.
·I deeply thank you in advance for your time and effort you take from youself to help.· It speaks volumes about the children your parents taught and raised.· Meanwhile, back to the breadboard!
··· ·

Comments

  • AlWilliamsAWCAlWilliamsAWC Posts: 135
    edited 2004-08-02 20:03
    It looks like you have a fair start. What you seem to be lacking is some variables. For example:

    stepcount var byte
    stepcount=0

    DO
    if IN3=1 then
    stepcount=stepcount+1
    IF stepcount<=3 then
    HIGH 14
    PAUSE 3000
    LOW 14
    END IF
    IF stepcount >3 AND stepcount<=5 THEN
    ' do relay Y
    END IF
    ' put more IFs here
    Do
    Loop Until IN3=0
    END IF
    LOOP

    There are more elegant ways to do this, but I wanted to stay close to your code as possible. For example, you could use X on 13, Y on 14, and Z on 15 and do something like HIGH X+stepcount/3 instead of the IF, but don't worry about that yet. First, see if I've correctly guessed your intent and then see if my extra code makes sense to you. If it does, see if you can replicate it for Y and Z.

    Regards,

    Al Williams
    AWC
    * New Kits:
    http://www.awce.com/kits.htm
  • Hard TimesHard Times Posts: 7
    edited 2004-08-02 20:35
    YES! YES! YES! Thank you so very much! I think I'll be able to figure it out from here. Where I was stuck at was your line of stepcount = 0. By the way, as this is my first code ever, it's more than elegant to me!!!
    You Sir, have made my day.
    Thank you,
    Bill
  • AlWilliamsAWCAlWilliamsAWC Posts: 135
    edited 2004-08-02 20:40
    Anytime. Since you are new, I'll point out the unofficial Stamp FAQ at http://www.wd5gnr.com/stampfaq.htm which I maintain. You might also enjoy the Stamp project of the month which is sometimes simple and sometimes complex at http://www.awce.com/som.htm.

    Regards,

    Al Williams
    AWC
    http://www.awce.com
    ·
Sign In or Register to comment.