KEYBOARD Input

HEDGEHEDGE Posts: 8
edited September 2008 in BASIC Stamp Vote Up0Vote Down
Is it possible to make the BS2 perform a certain action when a keyboard button is pressed?· I want to control several servos with different keyboard letters.

Comments

  • 7 Comments sorted by Date Added Votes
  • Steph LindsaySteph Lindsay Posts: 759
    edited September 2008 Vote Up0Vote Down
    Hi Hedge,
    1. Do you mean to:
      Attach a keyboard directly to your BASIC Stamp, or
    2. Use the keyboard on your PC while the BASIC Stamp is connected to the PC via a serial or USB port?
    If you mean #2, you can do this easily via the Debug Terminal's Transmit Windowpane, using the DEBUGIN command.·

    -Stephanie
  • Mike GreenMike Green Posts: 22,776
    edited September 2008 Vote Up0Vote Down
    What do you mean by "keyboard"? If you mean the PC's keyboard, then you can use DEBUGIN to receive a character from the debug window of the Stamp Editor (or other similar terminal emulator). Read the chapter on the DEBUGIN statement in the Stamp Basic Manual. You can compare the received character to whatever you want using some IF statements or a SELECT statement and perform whatever action you choose.

    If you mean a separate keyboard attached to the Stamp, you can do this too. You can buy a PS/2 keyboard adapter that attaches to a Stamp via a serial connection. You'd use a SERIN statement to receive the typed character.

    There are articles in the Nuts and Volts Columns series on attaching a keypad to a Stamp and scanning the keys.
  • Steph LindsaySteph Lindsay Posts: 759
    edited September 2008 Vote Up0Vote Down
    Just FYI, there is an activity in "Robotics with the Boe-Bot" with Continuous Rotation Servo control examples using DEBUGIN.· It's in Chapter 3, page 111.· You can dowload the book free from the Boe-Bot Robot Kit page.

    Also, in "What's a Microcontroller?" there is an activity using DEBUGIN with a Standard Servo, chapter 4, activity 2, on page 119.· You can download it·free·from the BASIC Stamp Activity Kit page.

    -Stephanie Lindsay

    Editor, Parallax Inc.
  • HEDGEHEDGE Posts: 8
    edited September 2008 Vote Up0Vote Down
    Thank You all for your input.· I am using the keyboard already connected to the PC to get the job done.· I will look into all of your suggestions and see what happens.· Im sure that they will work so thanks once again.· God Bless.
  • I know I wasn't apart of this form, but you guys helped a lot. My engineering teacher was no help at all and said to just google any questions we had and that brought me here. I never would have figured out the debug terminal if it weren't for you two giving the advise to look for the DEBUGIN section for the instruction manual.
  • There you go. Be it hardware or software that stymies you, the first thing to do is RTM. Parallax is outstanding in the amount and quality of manuals they provide.
  • MJMUCAMJMUCA Posts: 2
    edited October 29 Vote Up0Vote Down
    If you're wondering, this is what my code looks like.


    'Program: Keyboard Control
    '{$STAMP BS2}
    '{$PBASIC 2.5}

    X VAR Byte 'Declare variable
    Do until (X = "q" or X = "Q") 'Open Loop
    DEBUGIN X 'Accept an input keystroke
    Debug X 'Show it back to the user
    If X = "w" or X = "W" then
    Gosub Forward
    ElseIf X = "s" or X = "S" then
    Gosub Backwards
    ElseIf X = "a" or X = "A" then
    Gosub Left
    ElseIf X = "d" or X = "D" then
    Gosub Right
    ElseIf X = "h" or X = "H" then
    Gosub Honk
    EndIf 'Closes the conditional
    Loop 'Close the loop
    END 'End the program

    Forward:
    pulsout 12, 650 'right wheel forward
    pulsout 13, 850 'left wheel forward
    return 'Back to program

    Backwards:
    pulsout 12, 850 'right wheel backwards
    pulsout 13, 650 'left wheel backwards
    return 'Back to program

    Left:
    pulsout 12, 650 'right wheel forward
    pulsout 13, 650 'left wheel backwards
    return 'Back to program

    Right:
    pulsout 12, 850 'right wheel backwards
    pulsout 13, 850 'left wheel forwards
    return 'Back to program

    Honk:
    Freqout 4, 500, 2000 'honks for half of a second with a high pitch frequency
    return
Sign In or Register to comment.