Shop OBEX P1 Docs P2 Docs Learn Events
Inputting Letters via Serial Monitor to BS2 ? — Parallax Forums

Inputting Letters via Serial Monitor to BS2 ?

DonNohioDonNohio Posts: 24
edited 2015-02-10 10:10 in BASIC Stamp
Is it possible to input letters via Serial Monitor to BS2? I can not find any reference to this in the Help directory or in any of the topics. I have a working code using numbers. But it would be more user friendly if I could use letters.

Comments

  • Tracy AllenTracy Allen Posts: 6,662
    edited 2015-02-09 15:36
    Welcome to the forums!

    Sure, the BS2 can accept letters. There are several ways to do it. Here is an example that responds to individual letters that a user types in at a terminal in response to various options...
    SEROUT 16,sbaud,["(L)og  (V)iew  (Z)oom  (O)ffload (N)ewRun  (C)lock  (P)arams  (fF)eed  (U)SBkey",CR,REP LF\lfb,">",BELL]
    SERIN 16,sbaud,timeout,goIfTimeout,[char]  ' user choice, add WAIT ("PW") if password required
     IF char>$60 AND char<$7b THEN char.BIT5=0       ' -> uppercase
      ix=15     ' this if not in list
      LOOKDOWN char, ["!$NOLVZCFDPU"],ix    ' converts the letter entered by user into a numerical index
      BRANCH ix,[bulkErase,offloadBackup,newRun,offload,log,view,zoom,Setclock,feed,dump,parameters,USBvDrive]
      ' selects which subroutine to run
    
  • DonNohioDonNohio Posts: 24
    edited 2015-02-09 18:14
    Thanks for the welcome.

    I am relatively new to the stamp coding and will need a bit more explanation. I have included a piece of my working code:
    I am using a Pololu qik-2s9v1 motor controller. This project is going to add animation to my model RR. The mechanics are already under way.
     ENTER ONE OF THE FOLLOWING NUMBERS INTO THE DEBUG SCREEN FOR ONE OF THE FOLLOWING ACTIONS.
    ' #1 = FORWARD, #2 = REVERSE, #3 = STOP, #4 = TURN RIGHT, #5 = TURN LEFT
    ' #6 = SLOW FORWARD, #7 = SLOW REVERSE.
    '***********************************************************************************
    Main:
    
    DO
    
      DEBUGIN SNUM myNum
    
      SELECT myNum
    
       CASE 1
        ' FORWARD                      M0                            M1
        IF (myNum = 1) THEN SEROUT 14,32,[170,9,8,127]: SEROUT 14,32,[170,9,12,127]
        HIGH 0
        LOW  1
          DEBUG "FORWARD"
          DEBUG CR
    
       CASE 2
        ' REVERSE                      M0                             M1
        IF (myNum = 2) THEN SEROUT 14,32,[170,9,10,127]: SEROUT 14,32,[170,9,14,127]
          HIGH 1
          LOW  0
          DEBUG "REVERSE"
          DEBUG CR
    
       CASE 3
        ' STOP                         M0                           M1
        IF (myNum = 3) THEN SEROUT 14,32,[170,9,10,0]: SEROUT 14,32,[170,9,14,0]
          LOW  0
          LOW  1
          DEBUG "STOP"
          DEBUG CR
    
  • DonNohioDonNohio Posts: 24
    edited 2015-02-09 18:37
    I just read how to properly post code. Sorry:(
  • ercoerco Posts: 20,256
    edited 2015-02-09 20:51
    DonNohio wrote: »
    I just read how to properly post code. Sorry:(

    No worries. If you like, you can always edit your previous post with the code.

    Just put [co de] right before your program and [/co de] after, but don't use spaces like I did.
  • DonNohioDonNohio Posts: 24
    edited 2015-02-09 21:43
    That is better :)
    I am getting close to getting my code to work.
  • DonNohioDonNohio Posts: 24
    edited 2015-02-10 06:46
    I should have stated Debug Terminal instead of Serial Monitor. Serial Monitor is the term the "Other Guys" use.
  • DonNohioDonNohio Posts: 24
    edited 2015-02-10 07:46
    I have been treading water for the past hour or so. The code runs to the first selection(Forward) then stops and will not respond to the other letters. I feel there is a problem in lines 14- 16. Here is my code.
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    ' 2/10/2015
      char  VAR    Byte
      idx   VAR    Byte
    
      OUTPUT      0        'BICOLOR LED
      OUTPUT      1        'BICOLOR LED
    
    
    
     DEBUG CLS, "(F)orward (B)ackward (H)alt ",CR
     Main:
      DEBUGIN char
      IF (char>$40 AND char<$5b) THEN char.BIT5 = 15      ' Letters A - Z  Uppercase
      LOOKDOWN char,["!$BFH"],idx                         ' Converts the letter entered by user into a numerical index.
     BRANCH idx,[_Forward, _Backward, _Halt]              ' Selects which subroutine to run.
      END
    
     _Forward:
      HIGH 1
      LOW  0
      DEBUG "FORWARD"
      DEBUG CR
      END
    
     _Backward:
      HIGH 0
      LOW  1
      DEBUG "BACKWARD"
      DEBUG CR
      END
    
     _Halt:
      LOW  0
      LOW  0
      DEBUG "STOP"
      DEBUG CR
      END
    
  • davejamesdavejames Posts: 4,047
    edited 2015-02-10 07:52
    Hi Don,

    Each of the movement routines end with an "END", which puts the Stamp into a low-power shutdown mode.

    I would suggest using GOSUB/RETURN for the movement routines (check the Reference manual or Help in the Stamp IDE).

    And welcome to the Forum.

    DJ
  • Tracy AllenTracy Allen Posts: 6,662
    edited 2015-02-10 08:33
    You were already on track with your original program, very close indeed. The SELECT..CASE format is a good option. It's always good to post what you have already done, as a starting point, because there are so many different ways to do things.
    [size=1]ENTER ONE OF THE FOLLOWING NUMBERS INTO THE DEBUG SCREEN FOR ONE OF THE FOLLOWING ACTIONS.
    [color=red]' F or f = forward, R or r = reverse, S or s = stop, and so on[/color]
    ' #1 = FORWARD, #2 = REVERSE, #3 = STOP, #4 = TURN RIGHT, #5 = TURN LEFT
    ' #6 = SLOW FORWARD, #7 = SLOW REVERSE.
    '***********************************************************************************
    Main:
    
    DO
    
      DEBUGIN myNum
      
       SELECT myNum
    
       [color=red]CASE "F","f"[/color]
        ' FORWARD                      M0                            M1
        IF (myNum = 1) THEN SEROUT 14,32,[170,9,8,127]: SEROUT 14,32,[170,9,12,127]
        HIGH 0
        LOW  1
          DEBUG "FORWARD"
          DEBUG CR
    
       [color=red]CASE "R","r"[/color]
        ' REVERSE                      M0                             M1
        IF (myNum = 2) THEN SEROUT 14,32,[170,9,10,127]: SEROUT 14,32,[170,9,14,127]
          HIGH 1
          LOW  0
          DEBUG "REVERSE"
          DEBUG CR
    
       [color=red]CASE "S","s"[/color]
        ' STOP                         M0                           M1
        IF (myNum = 3) THEN SEROUT 14,32,[170,9,10,0]: SEROUT 14,32,[170,9,14,0]
          LOW  0
          LOW  1
          DEBUG "STOP"
          DEBUG CR[/size]
    

    In that scheme, you'll have to come up with single letter alternatives for slow forward and slow backward. Oh, it may not be clear from the Stamp manual, but the instruction
    DEBUGIN myNum
    receives one byte, an ascii code, from the serial input.
  • DonNohioDonNohio Posts: 24
    edited 2015-02-10 09:52
    Got it :)
    Thanks for all your help! I have dropped the slow speeds for now, may not need them. Here is the code.
    How do you put a SOLVED on the thread?
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    '   2/10/2015
    
    
      myNum   VAR    Byte
    
    'ENTER ONE OF THE FOLLOWING LETTERS INTO THE DEBUG SCREEN FOR ONE OF THE FOLLOWING ACTIONS.
    ' F or f = forward, R or r = reverse, S or s = stop.
    '***********************************************************************************
    DO
    
      DEBUGIN myNum
    
      SELECT myNum
    
       CASE "F"
        ' FORWARD                      M0                            M1
        IF (myNum = 1) THEN SEROUT 14,32,[170,9,8,127]: SEROUT 14,32,[170,9,12,127]
        HIGH 0
        LOW  1
          DEBUG "FORWARD"
          DEBUG CR
    
       CASE "R"
        ' REVERSE                      M0                             M1
        IF (myNum = 2) THEN SEROUT 14,32,[170,9,10,127]: SEROUT 14,32,[170,9,14,127]
          HIGH 1
          LOW  0
          DEBUG "REVERSE"
          DEBUG CR
    
       CASE "S"
        ' STOP                         M0                           M1
        IF (myNum = 3) THEN SEROUT 14,32,[170,9,10,0]: SEROUT 14,32,[170,9,14,0]
          LOW  0
          LOW  1
          DEBUG "STOP"
          DEBUG CR
    
      ENDSELECT
    
    LOOP
    
  • davejamesdavejames Posts: 4,047
    edited 2015-02-10 10:10
    DonNohio wrote: »
    How do you put a SOLVED on the thread?

    Edit your original post in the "advanced" mode. You'll find a selector box toward the top that will have a "solved" option.
Sign In or Register to comment.