Shop OBEX P1 Docs P2 Docs Learn Events
Mode Select help. — Parallax Forums

Mode Select help.

jdoleckijdolecki Posts: 726
edited 2009-01-20 22:50 in BASIC Stamp
How do i write a program to select three different machine modes from one push button?

Machine has 3 modes

Stop
Run
Automatic

Push Push button on input P0 and the machines to the next mode.

I have been readig "whats a micro controller " book but cant find any examples.

thanks

john

·

Comments

  • SRLMSRLM Posts: 5,045
    edited 2009-01-19 00:53
    The same way that your mouse button works. A single click does one thing, a second click within a specified timeframe, and (in your case) a third click within another specified timeframe does another thing.
  • Mike GreenMike Green Posts: 23,101
    edited 2009-01-19 00:59
    You need something like this for a button connecting to Vss with a pullup to Vdd:
      state = 0
    check:
      button P0,0,255,0,work,0,check
      state = (state + 1) // 3
      goto check
    


    This just sits in a loop waiting for the button to be pressed. When pressed, it increments "state" wrapping around at 3. You'll need to add something to this loop to give feedback to the user, perhaps a red/green LED that lights red for stop, green for run, and orange (red and green) for automatic. You'd need to add other code to this loop to provide for the actual action to be performed.
  • jdoleckijdolecki Posts: 726
    edited 2009-01-20 21:03
    Please Explain, I have been doing different variations of the this program along with the ones in the book but they dont explaine everything .
    I found an example in the book and im trying to adapt thay to what i need but still having trouble.

    You Wrote:

    ··state·=·0
    check:
    ··button·P0,0,255,0,work,0,check
    ··state·=·(state·+·1)·//·3
    ··goto·check

    State = 0·· This line set's the "State"· word to zero correct? Why is it called "State" can it be called something else? What is state, a memory location?

    Check:·· ( is the programs name?)

    Button ( Why is it called Button? can it be called something else?)
    P0,···· ·( Is the input, i get that)
    0,······· ( is the beginning of the Word bit?)
    255,··· (255 max·of the word?)
    0,······ ( I dont understand)
    Work,· ( I dont understand)
    0,·······(I dont understand)
    check··( check is the name of the program but why is it here?)


    state =······ ( Again what is state)
    ( state +1)··( Adds 1 to the "state" count)
    // 3··········· ( means count to 3 before starting over?)
    goto check···( returns back to the beginning of the program)


    Thanks for taking time to explain.

    ·
  • Mike GreenMike Green Posts: 23,101
    edited 2009-01-20 21:15
    There's a notion in engineering and programming of the "state" of a system. This is some kind of value that represents all the different things in a system, whether mechanical or electronic, that have some kind of memory associated with them. In this case, we have a "machine" with 3 possible states (never pushed, pushed once, pushed twice) with the states repeating in order every 3 button pushes. In this code fragment, I've represented the state with a variable called "state" that can have 3 possible values (0, 1, 2) that repeat. For the details of the BUTTON statement, read the chapter in the Stamp Basic Manual first, then come back with any unanswered questions. The "//" operator takes the remainder on a division (in this case by 3). Read the section in the manual on it ("//") if you don't understand it.

    The label "check:" is pretty simple Basic. I suggest you download a copy of the "What's a Microcontroller?" tutorial and go through it. It's a good introduction to the basics of Basic for the Stamps.

    Post Edited (Mike Green) : 1/20/2009 9:20:33 PM GMT
  • jdoleckijdolecki Posts: 726
    edited 2009-01-20 22:16
    Thanks, I cant belive i missed the Button statement.
  • jdoleckijdolecki Posts: 726
    edited 2009-01-20 22:50
    Thank I found the "PBASIC Command Reference·" and it explains·everything i need to know.

    Last Question.

    Is "Syntax" the correct term to use when talking about the "button" command?

    The data/numbers after the·Button command are called what?·Variables?

    Thanks again
Sign In or Register to comment.