Shop OBEX P1 Docs P2 Docs Learn Events
how to send a serial command with the press of a button — Parallax Forums

how to send a serial command with the press of a button

Chris SavageChris Savage Parallax EngineeringPosts: 14,406
edited 2006-04-03 22:21 in BASIC Stamp
Everytime an active-high button connected to P0 is pressed it will send the text to the serial I/O line.
' {$STAMP BS2}
' {$PBASIC 2.5}
 
DO
  IF IN0 = 1 THEN
    SEROUT LCD, Baud, [noparse][[/noparse]"Hello World!"]
    PAUSE 100
  ENDIF
LOOP

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com

Comments

  • allanlane5allanlane5 Posts: 3,815
    edited 2006-04-02 03:20
    ButtonState VAR BIT

    ButtonState = 0

    IF MyButton = 1 THEN
    IF ButtonState = 0 THEN
    SEROUT 16, 63864, [noparse][[/noparse]"High",13]
    ButtonState = 1
    ' ELSE, do nothing
    END IF
    ELSE ' MyButton == 0 (not pressed)
    IF ButtonState = 1 THEN
    ButtonState = 0
    END IF
    END IF

    The idea behind this is you only output ONE message, when the system
    first detects the button is pressed (goes high, I'm assuming here).
    As long as you hold the button down, ButtonState stays 1, and you don't
    output any more messages.

    It's only after you Release the button, the system reads that, and
    sets ButtonState to zero -- After that, you can press the button
    again and get ONE more message out.
  • max9864max9864 Posts: 4
    edited 2006-04-02 03:24
    I'm hoping someone could give me some pointers on how to send a serial command with the press of a button. I can scan and look for the button to go high or low. But don't know how to send a serial command upon the trigger of the button. Any information would be extremely appreciated.

    Post Edited By Moderator (Chris Savage (Parallax)) : 4/2/2006 3:18:21 AM GMT
  • max9864max9864 Posts: 4
    edited 2006-04-03 01:42
    Thank-you Chris,
    I used your example, now I have two buttons that will change the parameters of a Microscan 820 UPC scanner by sending one command with one button and the other command with the other button. Works like a Champ.

    ' {$STAMP BS2sx}
    ' {$PBASIC 2.5}
    Start:
    IF IN0=0 THEN
    SEROUT 16,8432, [noparse][[/noparse]"<KL1><A>"]
    PAUSE 500
    ENDIF
    IF IN1=0 THEN
    SEROUT 16,8432, [noparse][[/noparse]"<KL2><A>"]
    PAUSE 500
    ENDIF
    GOTO Start

    Your the Man Chris!
    Thanks again
  • Jeff DegeJeff Dege Posts: 85
    edited 2006-04-03 04:41
    ButtonState VAR BIT

    ButtonState = 0

    IF MyButton = 1 AND ButtonState = 0 THEN
    SEROUT 16, 63864, [noparse][[/noparse]"High",13]
    ButtonState = 1
    ELSEIF MyButton = 0 THEN
    ButtonState = 0
    END IF
  • max9864max9864 Posts: 4
    edited 2006-04-03 22:21
    Thanks Jeff,

    How would your example work with 2 buttons. As you can see I'm far from a programming guru, but I'm giving it hell.
Sign In or Register to comment.