Shop OBEX P1 Docs P2 Docs Learn Events
Bs2sx — Parallax Forums

Bs2sx

Blackbird455Blackbird455 Posts: 124
edited 2007-10-31 18:24 in BASIC Stamp
I originally asked this about the BS1...........maybe it'll go over a little better this time...........


· Basically I need a code "snippett" or EXAMPLE , not for someone to write the entire thing for me.....

·I need to have ONE button tied to PIN 0, ................... once power is applied, she starts running, and then I push the button........up to 30 times.
Every time that the button is pushed, a new set of instructions runs, example:

···· DO
···· TOGGLE 2········ 'first set after power up, or "main"
···· PAUSE 60
···· LOOP
···· IF (heres where I need the help) THEN???

···· DO··················'just an example of one of thirty or so sets of instructions·
···· TOGGLE 3
···· PAUSE 20
···· TOGGLE 5
···· PAUSE 60
···· LOOP

I would really appreciate some more help on this, I know that I am just overlooking something simple.
Thanks

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Noli nothis permittere te terere

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2007-10-31 14:23
    How about something like:
    start:
    do ' Action #1
      toggle 2
      pause 60
    loop until in0 = 1
    do ' Wait for button to be released
    loop until in0 = 0
    do ' Action #2
    '   and so on
    


    The only thing to be careful of is that you have to hold the button in long enough for the snippet to finish. It looks like all of them are short so that shouldn't be a problem.
  • Blackbird455Blackbird455 Posts: 124
    edited 2007-10-31 14:46
    thanks Mike , I'll try it.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Noli nothis permittere te terere
  • Mike GreenMike Green Posts: 23,101
    edited 2007-10-31 14:59
    You might also look at the BUTTON statement in PBasic. This does debouncing for you if you have very "bouncy" buttons. You'd put the BUTTON statement at the end of the loop (before the LOOP) and it would work like a GOTO to a label on the next DO statement when the debounced button push was detected. In this case, you wouldn't need the UNTIL clause on the LOOP statement.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2007-10-31 18:24
    Well, the code would be a little different, but you could have it so when you exit the button loop each time a counter is incremented and a BRANCH instruction sends the code to each sub. Each destination address would have to terminate by going to the label, “Main:”.

    Main:
      DO
        TOGGLE 2            ' What does this do?
        PAUSE 60            ' Flash an LED?
      LOOP WHILE IN0 = 0    ' Wait for active-LOW button
    
      PAUSE 150             ' Debounce delay
    
      index = index + 1     ' Increment index counter
      IF index = 32 THEN index = 0 ' Check for wrap-around
    
      BRANCH (index – 1), [noparse][[/noparse]address1, address2, address3, etc] ' Account for +1 offset
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support


    Post Edited (Chris Savage (Parallax)) : 10/31/2007 6:29:31 PM GMT
Sign In or Register to comment.