The Hackaday BASIC interpreter is based on the uBASIC project by Adam Dunkels. This provided a tokenizer and the most rudimentary words needed for the language to operate. From there, Jaromir Sukuba greatly expanded the word set to take advantage of the best the badge hardware has to offer.
The reference for all of the words is listed below. You may also see examples of these words in use by viewing the example code project log.
Of Note:
- Code in the program buffer can be viewed one page at a time by typing
more
. You can overwrite lines just by typing the line number at the prompt along with your new commands. It is recommended that you number every 10 lines or more so that you can add commands in between them as you develop your code. - The
memclr
word will clear the code currently in the program buffer. - There are two print commands.
print
will not include a line feed,println
will include a line feed
BASIC Word List:
Standard Words:
print
println
if
goto
gosub
return
for
next
end
let<br>
rem
Badge Custom Words
led X,Y
- control LED, X[0..2] RGB, Y[0..1] on/offtune A,B,C,D
- plays tones A, B, C for duration Dclrscr
- clear screensetxy X,Y
- set cursor at X,Ywait X
- wait for X mscolor X,Y
- X=Foreground, Y=Background using EGA 16-color palettechr X
- prints character with ASCII representation Xtermt X
- sets VT100 terminal on or off (1-on, 0-off)termup
- forces screen refresh, if VT100 terminal is offrnd X
- function to return random number 0..Xein X
- function to return value of expansion pin Xeout X,Y
- control expansion pin, X[0..3], Y[0..1] on/offedr X,Y
- sets expansion pin function X[0..3], Y[0..1] output/inputuin X
- function to return received byte from serial port, if X=0, function is non-blocking, if X=1, function is blockinguout X
- outputs value X to serial port as single byteinput "string"
- prints string and returns user entered valuepeek X
- returns value from memory location Xpoke X,Y
- write value Y into memory, on location Xcursor X
- turns cursor on (X=1) or off (X=0)kin X
- function to return byte from keyboard, if X=0, function is non-blocking, if X=1, function is blocking
BASIC CLI commands
run
- runs programsave X
- Save program buffer to flash. There are 16 slots: X[0..15]load X
- Load program into buffer from flash. There are 16 slots: X[0..15]list
- list whole programmore
- list program by pagesmemclr
- clears all code from the program bufferfree
- prints amount of free program buffersload
- load new program into buffer from serial portssave
- output program buffer via serial porthelp
- short help
Aliases
In order to save you some typing, we defined some aliases for functions
print
-pnt
println
-ptl
clrscr
-cls
,clr
input
-inp
setxy
-sxy
return
-ret
cursor
-cur
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.
The only real problem is - no strings!
Are you sure? yes | no
I can't get the `kin` command working :(
Could somebody provide a simple example of using kin? In my case, `println kin 1` doesn't block. It returns 1 and continues execution...am I missing something, or is it a bug?
I am using the hackaday basic interpreter and typing the code to the badge directly...
Are you sure? yes | no
Something like
10 println kin 0
20 wait 500
30 goto 10
writes 0 to console every 500ms, except of when you press key, ASCII value of key in decimal format will be printed. For blocking variant, try
10 println kin 1
20 goto 10
This should wait for keypress and print out value only when key is pressed. Note that kin command exists in firmware version 1.02 and higher - I made this enhancement during the conference since people asked for it.
Are you sure? yes | no
Indeed, a string, or an array or chars - only needs indexing to be an array so its easy to implement.
Ahhh, logical_name$(i,n) how I miss you. Python is clunky... ;-)
Tentacles crossed it goes off royally, wish I could drop in on these things. :-)
Are you sure? yes | no
REM and INPUT have now be implemented. What does DIM do?
I had just been using a lot of IF statements to get around the lack of ELSE. Maybe you can implement DIM and ELSE as your badge hack ;-)
Are you sure? yes | no
DIM declares an array.
dim a$(10) creates an array of 10 character strings
Are you sure? yes | no
(Oops, meant to reply to @ðeshipu before)
DIM is actually what I was looking for a couple of days ago. Was trying to figure out how you do Game of Life in basic and only have access to 26 variables (single letters only).
At this point we've frozen features because we need to make sure we have a fully tested image when badges are programmed next week. Maybe a future firmware (or a hack at the con) will have this.
Are you sure? yes | no
I guess you could do game of life on strings.
Are you sure? yes | no
No DIM? What about ELSE? Or REM? No INPUT?
Are you sure? yes | no