Examples of RBASIC™ Programs

Example 1 - A Simple Spectrum Scope

startfreq=88: endfreq=108 : step=0.1
count=(endfreq-startfreq)/step+1
graph$="Spectrum scope"
OPENGRAPH(graph$,count,120)
RMODE$="FMW"

FOR i=0 TO count
rfr=startfreq
CLEARV(graph$,i)
signal=rss
SETCOLOR(graph$,signal*2+15,signal*2+15,0)
LINE(graph$,i,signal,i,0)
startfreq=startfreq+step
DELAY(100)
NEXT i


Example 2 - An Even Simpler Spectrum Scope

graph$="FM spectrum"
OPENGRAPH(graph$,400,120)
SETCOLOR(graph$,0,255,0)
RMODE$="FMW"

@loop
SETP(graph$,0,0)
FOR i=0 TO 400
# starting freq is 88 MHz, 50 kHz steps
RFREQ=88+i*0.05
CLEARV(graph$,i)
PLOT(graph$,i,RSS)
NEXT i
GOTO loop


Example 3 - Hit Counter

startfreq=88 : count=5: delta=2
DIM hits(count+1)

PRINT "Enter threshold"
INPUT threshold
times=0
@loop
times=times+1
FOR i=0 TO count
rfrequency=startfreq+i*delta
DELAY(100)
level=rsstrength
IF level>threshold THEN hits[i]=hits[i]+1
NEXT i
a$="("+str$(times)+") "
FOR i=0 TO count
a$=a$+str$(startfreq+i*delta)+"MHz:"+FORMAT$(100*hits[i]/times,5,2)+"%"+spc$(5)
NEXT i
DISP a$
GOTO loop


Example 4 - A Simple Signal Logger

logfile$="c:logfile.txt"
oldsignal= -123
oldfreq= -123

@loop
signal=rsstrength:freq=rfrequency
if (signal=oldsignal) AND (oldfreq=freq) THEN GOTO loop
oldfreq=freq : oldsignal=signal
a$=DATE$+" "+TIME$+", "+str$(rfrequency)+" MHz, signal level="+str$(signal)
OPENWRITE(logfile$)
WRITE(logfile$,a$)
CLOSE(logfile$)
DISP a$
GOTO loop


Example 5 - Graphics

(Note: This example program does not interface with the radio, so you can run it even without it, to demonstrate how simple it is to create graphics in RBASIC.)

g$="Screen"
size=300: count=10
DIM data(count,4)
DIM delta(4)
FOR i=0 TO 3:delta[i]=RND*5:NEXT i
FOR i=0 TO 3:data[0,i]=RND*size:NEXT i
OPENGRAPH(g$,size,size)
r=255:g=r:b=r

@loop
SETCOLOR(g$,r,g,b)
LINE(g$,data[0,0],data[0,1],data[0,2],data[0,3])
SETCOLOR(g$,0,0,0)
LINE(g$,data[count-1,0],data[count-1,1],data[count-1,2],data[count-1,3])

FOR i=count-1 TO 1 STEP -1
FOR j=0 TO 3:data[i,j]=data[i-1,j]:NEXT j
NEXT i

FOR i=0 to 3: data[0,i]=data[1,i]+delta[i]
IF data[0,i]<0 OR data[0,i]>=size THEN data[0,i]=data[0,i]-delta[i]:delta[i]= -(delta[i]/ABS(delta[i])*(RND*15+5)):r=RND*255:g=RND*255:b=RND*255

NEXT i
GOTO loop


Example 6 - A Single-Line Program

Can a single-line program do anything useful? This one does, it shows the ANSI printable character table on the Console screen:

for i=38 to 255: print str$(i)+"="+chr$(i): next i


See also user-supplied RBASIC public-domain applications here.