Close

BASIC Program Examples

A project log for Badge for Hackaday Conference 2018 in Belgrade

In the 1980's, you had to know programming to use computers. They were used for... guess what? Computing! Want to see how it looked?

Mike SzczysMike Szczys 05/14/2018 at 21:470 Comments

Print out all possible characters:

10 for i=32 to 255
20 chr i
30 next i

 Bling the LEDs randomly (d is diode [0..2], s is state [0..1])

10 d = rnd 2
20 s = rnd 1
30 led d,s
40 print “Press BRK to return to BASIC prompt”
50 wait 100
60 goto 10

 Play random Major triads:

10 let i = rnd,77
20 if i<53 then goto 10
30 tune i,i+4,i+7,400
40 goto 10

 Scroll some text. The space before the text erases the previous character in that position:

10 let i=0
20 color 14,12
30 clrscr
40 setxy i,0
50 print " Scroller"
60 i=i+1
70 wait 150
80 if i<32 then goto 40
90 color 15,0

 Bounce ball on screen. Shows moving to different areas on screen, changing color, using delays and subroutines, and manual screen refresh (term 0 shuts off automatic scanning, termup triggers manual refresh) for a smoother animation than the scroll text example:

5 termt 0
10 let x = 39
20 let d = 0
30 clrscr
40 color 11,0
50 setxy x,10
60 chr 32
70 if d = 1 then gosub 200
80 if d = 0 then gosub 300
90 chr 254
95 termup
100 if x = 0 then d = 1
110 if x = 39 then d = 0
120 wait 50
130 goto 50
200 x = x + 1
210 return
300 x = x - 1
310 setxy x,10
320 return

Function to read byte from serial port and print it out

10 println uin 0
20 wait 500
30 goto 10

This one starts printing zero every 500ms, if there is any incoming byte from serial port, it gets written out.

If you change uin parameter from 0 to 1, function gets blocking, ie. execution doesn't continue until serial byte is received. In that case, only when byte is received interpreter prints anything out.

The same example can be used to read data from keyboard, the function used is called kin.

Discussions