Syntax: DEBUGIN InputData
Retrieve information from the user via the Debug Terminal window within the BASIC Stamp editor program.
BS2, BS2e, BS2sx, BS2p, and BS2pe | BS2px | |
Serial Protocol | Asychronous 9600 baud, N, 8, 1 Inverted polarity, Raw Data |
Asychronous 19.2 kBaud, N, 8, 1 Inverted polarity, Raw Data |
Related Commands |
DEBUGIN provides a convenient way for your BASIC Stamp accept input from the use via the Debug Terminal. DEBUGIN can wait for, filter and convert incoming data in powerful ways, using the same techniques and modifiers as SERIN.
This simple example waits for a number from the user, then prints a message the specified number of times:
lines VAR Nib idx VAR Nib Main: DEBUG CLS, "How many lines to print (1 - 5)? --> " DEBUGIN DEC1 lines IF ((lines >= 1) AND (lines <= 5)) THEN DEBUG CR, CR FOR idx = 1 TO lines ' print message specified times DEBUG DEC1 idx, ". " DEBUG "BASIC Stamp!", CR NEXT END ' end of program ELSE DEBUG CR, "Invalid entry!" ' warning message PAUSE 2000 ' wait 2 seconds GOTO Main ' get another entry ENDIF
After you download this program, the BASIC Stamp Editor will open a Debug Terminal on your PC screen and wait for an entry from the user. Since the DEC1 modifier is used with DEBUGIN, the program will ignore all keys except "0" - "9". If the value entered is between 1 and 5, the message will be printed, otherwise the program will display an "Invalid entry" message, then loop back and wait for another entry.
DEBUGIN is actually a special case of the SERIN instruction. It is set for inverted (RS-232-compatible) serial output through the programming connector (the SIN pin) at 9600 baud (BS2, BS2e, BS2sx, BS2p, and BS2pe) or 19.2 kBaud (BS2px), no parity, 8 data bits, and 1 stop bit. For example,
DEBUGIN DEC1 lines
...is exactly like:
SERIN 16, $4054, [DEC1 lines]
...in terms of function (on a BS2). The DEBUGIN line actually takes less program space, and is obviously easier to type.
The tables below list all the available conversion formatters and special formatters available to the DEBUGIN command. See the SERIN command for additional information and examples of their use.
Conversion Formatter | Type of Number | Numeric Characters Accepted | Notes |
DEC{1..5} | Decimal, optionally limited to 1 - 5 digits | 0 through 9 | 1 |
SDEC{1..5} | Signed decimal, optionally limited to 1 - 5 digits | -, 0 through 9 | 1,2 |
HEX{1..4} | Hexadecimal, optionally limited to 1 - 4 digits | 0 through 9, A through F | 1,3 |
SHEX{1..4} | Signed hexadecimal, optionally limited to 1 - 4 digits | -, 0 through 9, A through F | 1,2,3 |
IHEX{1..4} | Indicated hexadecimal, optionally limited to 1 - 4 digits | $, 0 through 9, A through F | 1,3,4 |
ISHEX{1..4} | Signed, indicated hexadecimal, optionally limited to 1 - 4 digits | -, $, 0 through 9, A through F | 1,2,3,4 |
BIN{1..16} | Binary, optionally limited to 1 - 16 digits | 0, 1 | 1 |
SBIN{1..16} | Signed binary, optionally limited to 1 - 16 digits | -, 0, 1 | 1,2 |
IBIN{1..16} | Indicated binary, optionally limited to 1 - 16 digits | %, 0, 1 | 1,4 |
ISBIN{1..16} | Signed, indicated binary, optionally limited to 1 - 16 digits | -, %, 0, 1 | 1,2,4 |
NUM | Generic numeric input; hex or binary number must be indicated | $, %, 0 through 9, A through F | 1,3,4 |
SNUM | Similar to NUM with value treated as signed with range -32768 to +32767 | -, $, %, 0 through 9, A through F | 1,2,3,4 |
Special Formatter | Action |
STR ByteArray \L {\E} | Input a character string of length L into an array. If specified, an end character E causes the string input to end before reaching length L. Remaining bytes are filled with 0s (zeros). |
WAITSTR ByteArray {\L} | Wait for a sequence of bytes matching a string stored in an array variable, optionally limited to L characters. If the optional L argument is left off, the end of the array-string must be marked by a byte containing a zero (0). |
SKIP Length | Ignore Length bytes of characters. |
Special Formatter | Action |
SPSTR L | Buffer length L bytes (up to 126) of serial characters to Scratchpad RAM, starting at location 0. Use GET to retrieve the characters. |
idx VAR Nib char VAR Byte Setup: DEBUG CLS, "Enter (4-character) passcode: " Main: DEBUGIN SPSTR 4 DEBUG CLS, "Checking: " FOR idx = 0 TO 3 GET idx, char DEBUG char NEXT END
The example above will redirect four characters from the Debug Terminal input to Scratchpad locations 0 - 3.
BASIC Stamp Help Version 2.5.4
Copyright © Parallax Inc.
8/8/2012