Skip to content

Latest commit

 

History

History
78 lines (72 loc) · 2.9 KB

BasicCheatsheet.md

File metadata and controls

78 lines (72 loc) · 2.9 KB

BASIC Language

Variables names can be up to 8 alphanumeric characters but start with a letter e.g. a, bob32 String variable names must end in $ e.g. a$, bob32$ Case is ignored (for all identifiers). BOB32 is the same as Bob32. print is the same as PRINT

Array variables are independent from normal variables. So you can use both:

LET a = 5
DIM a(10)

There is no ambiguity, since a on its own refers to the simple variable 'a', and a(n) referes to an element of the 'a' array.

Arithmetic operators: + - * / MOD
Comparisons: <> (not equals) > >= < <=
Logical: AND, OR, NOT

Expressions can be numerical e.g. 5*(3+2), or string "Hello "+"world". Only the addition operator is supported on strings (plus the functions below).

Commands

PRINT <expr>;<expr>... e.g. PRINT "A=";a
LET variable = <expr> e.g. LET A$="Hello".
variable = <expr> e.g. A=5
LIST [start],[end] e.g. LIST or LIST 10,100
RUN [lineNumber]
GOTO lineNumber
REM <comment> e.g. REM ** My Program ***
STOP
CONT (continue from a STOP)
INPUT variable e.g. INPUT a$ or INPUT a(5,3)
IF <expr> THEN cmd e.g. IF a>10 THEN a = 0: GOTO 20
FOR variable = start TO end STEP step
NEXT variable
NEW
GOSUB lineNumber
RETURN
DIM variable(n1,n2...)
CLS
SLEEP put terminal in low power mode, exit with power button
PAUSE milliseconds
POSITION x,y sets the cursor
PIN pinNum, value (0 = low, non-zero = high)
PINMODE pinNum, mode ( 0 = input, 1 = output)
LOAD (from internal EEPROM)
SAVE (to internal EEPROM) e.g. use SAVE + to set auto-run on boot flag
LOAD "filename", SAVE "filename, DIR, DELETE "filename" if using with external EEPROM or SD card. Concerning SD card, the filename is limited to 8 characters. the software adds the ".BAS" extension. Concerning SD card, the filename is limited to 8 characters. the software adds the ".BAS" extension.
MOUNT force the detection of the SD card. Necessary if it has been inserted when the terminal is running. Mount is made at reset and when restarting after a sleep
UNMOUNT close all the files and prepare the card to be extracted. UNMMOUNT is made when entering sleep.
TONE frequency_to_play Play a sound in the piezo buzzer
NOTONE stop the tone
POKE address, value write value in memory at address

"Pseudo-identifiers"

INKEY$ - returns (and eats) the last key pressed buffer (non-blocking). e.g. PRINT INKEY$
RND - random number betweeen 0 and 1. e.g. LET a = RND

Functions

LEN(string) e.g. PRINT LEN("Hello") -> 5
ASC(string) e.g. PRINT ASC("ABCD") -> 65 (ASCII code of A)
VAL(string) e.g. PRINT VAL("1+2")
INT(number) e.g. INT(1.5)-> 1
STR$(number) e.g. STR$(2) -> "2"
LEFT$(string,n)
RIGHT$(string,n)
MID$(string,start,n)
PINREAD(pin) - see Arduino digitalRead()
ANALOGRD(pin) - see Arduino analogRead()
PEEK(address) - display content of memory location address

Usually, a BASIC program can be halted with a CTRL+C. As there are no control keys on the terminal, the square root key has been chosen for that.