Shop OBEX P1 Docs P2 Docs Learn Events
How to read from Keyboard? — Parallax Forums

How to read from Keyboard?

HelpMeHelpMe Posts: 3
edited 2009-02-11 11:16 in BASIC Stamp
I·trying to so a remote control onto my sumobot which uses basic stamp 2.
Now what is my problem is i can not read from keyboard.
I·going to use "wasd" to control my sumobot while having the cable connect to sumobot. So now, can i read from keyboard when i press "w" then i do checking?
If you know the command, pls reply me as soon as possible because·i really need to·solve this problem fast. thanks

Comments

  • SRLMSRLM Posts: 5,045
    edited 2009-01-14 04:11
    You'll need to use the DEBUG command to read from your keyboard. From there, you can compare the received value against the expected value, and call subroutines like "TurnLeft". See the link below for more of an idea.

    http://forums.parallax.com/showthread.php?p=755918
  • HelpMeHelpMe Posts: 3
    edited 2009-01-18 11:30
    wow thanks to you
    i edit the program from your program
    now i can RC---remote control my sumobot using "wasd" key already.
    thanks

    my program is
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}

    'The purpose of this program is To use "wasd" key To control sumobot direction, promped
    'by the debug window. Note that you don't need to redownload the program everytime if
    'it's already on the BS2. You just need to open a debug window on the correct COM port.

    '
    [noparse][[/noparse] I/O Definitions ]
    LMotor PIN 13 ' left servo motor
    RMotor PIN 12 ' right servo motor
    out PIN 0
    '
    [noparse][[/noparse] Constants ]
    LFwdFast CON 900 ' left motor fwd; fast
    LFwdSlow CON 800 ' left motor fwd; slow
    LStop CON 750 ' left motor stop
    LRevSlow CON 700 ' left motor rev; slow
    LRevFast CON 500 ' left motor rev; fast

    RFwdFast CON 500 ' right motor fwd; fast
    RFwdSlow CON 700 ' right motor fwd; slow
    RStop CON 750 ' right motor stop
    RRevSlow CON 800 ' right motor rev; slow
    RRevFast CON 1000 ' right motor rev; fast
    '
    [noparse][[/noparse] Variables ]
    letter VAR Byte
    done VAR Byte
    '
    [noparse][[/noparse] Initialization ]
    Reset:
    LOW LMotor ' initialize motor outputs
    LOW RMotor
    PAUSE 2000 ' time to disconnect cable
    '
    [noparse][[/noparse] Program Code ]


    DEBUG "Use wasd key to control the sumobot", CR, "w to move forward",CR, "a to turn left", CR,
    "s to move reverse", CR, "d to turn right", CR, CR

    DO
    GOSUB _SendData
    LOOP

    'Send one char at a time
    _SendData:
    done = 0
    DEBUG CR, "You >> "
    DO WHILE done = 0
    DEBUGIN STR letter \1
    SEROUT out, 84, [noparse][[/noparse]letter, CR]

    IF(letter = 119)THEN 'if w is pressed'
    PULSOUT LMotor, LFwdFast
    PULSOUT RMotor, RFwdFast
    PAUSE 20
    done = 1
    ENDIF

    IF(letter = 97)THEN 'if a is pressed'
    PULSOUT LMotor, LStop
    PULSOUT RMotor, RFwdFast
    PAUSE 20
    done = 1
    ENDIF

    IF(letter = 115)THEN 'if s is pressed'
    PULSOUT LMotor, LRevFast
    PULSOUT RMotor, RRevFast
    PAUSE 20
    done = 1
    ENDIF

    IF(letter = 100)THEN 'if s is pressed'
    PULSOUT LMotor, LFwdFast
    PULSOUT RMotor, RStop
    PAUSE 20
    done = 1
    ENDIF
    LOOP
    RETURN
  • HelpMeHelpMe Posts: 3
    edited 2009-02-11 11:16
    Sorry to ask this,
    I have this Condition
    After i press "w" once (moving foward) until i press other key.
    Which mean how do i edit the program above to have a "continuous moving" until i press other command Key.
    If there is a way, pls send me tonite?
    Because my Supervisor today come out with this requirement and tommorow is my presentation........

    really

    HELP ME
Sign In or Register to comment.