Home 
TinyBricks 
Language 
Samples 
Screens 
Downloads 
Impressum 

 

 


 

 

 

 

 

 

 Hello World...
do
    print "Hello World!"
    pause 100
loop

  

 Accessing ports...
' SetPort <Port: 0..9>,<Config: 0=in/1=out>[,<Pullups: 1=pullup>]
setport 2,%11111111

' The main loop...
do
    if Port2 = $ff then 
        Port2 = 0
    else 
        Port2 = Port2 << 1 or 1 
    endif 

    pause 100 
loop

 

 PWM outputs used to control 8 RC servos...

' Hardware
#target TINYDISPLAY

' SetDisplay <Type: 0..4>
setdisplay
LCD_DOGM128x64               ' graphic display

' SetPWM <Channel: 0..7>,<Divider: 0..7>,<Period: 0..65535>
setpwm
0,7,60000                        ' rc-servo 0
setpwm 1,7,60000                        ' rc-servo 1
setpwm 2,7,60000                        ' rc-servo 2
setpwm 3,7,60000                        ' rc-servo 3
setpwm 4,7,60000                        ' rc-servo 4
setpwm 5,7,60000                        ' rc-servo 5
setpwm 6,7,60000                        ' rc-servo 6
setpwm 7,7,60000                        ' rc-servo 7

' The main loop
do

   pwm0 =
2500                          ' 2500..5000 -> 1.1ms..2.1ms
   pwm1 =
2850
   pwm2 =
3215
   pwm3 =
3570
   pwm4 =
3925
   pwm5 =
4285
   pwm6 =
4640
   pwm7 =
5000                  

   move 0,0
   
print #2,using("Servo0 = #.## ms",pwm0 / 2350.0)
   
print #2,using("Servo1 = #.## ms",pwm1 / 2350.0)   
   
print #2,using("Servo2 = #.## ms",pwm2 / 2350.0)   
   
print #2,using("Servo3 = #.## ms",pwm3 / 2350.0)   
   
print #2,using("Servo4 = #.## ms",pwm4 / 2350.0)   
   
print #2,using("Servo5 = #.## ms",pwm5 / 2350.0)   
   
print #2,using("Servo6 = #.## ms",pwm6 / 2350.0)   
   
print #2,using("Servo7 = #.## ms",pwm7 / 2350.0)    
loop

 

 Receive and parse serial stream...
' Use console window to send the following macro:
' a=10,b=20,c=30<CR>

' Port2.0 as output
setport 2,$01

' Variables
char strText[20]
byte nPos

' Init vars
nPos = 0

print chr(12),"Enter string like: x=10,y=20,z=30<CR>"

' The main loop
do
    ' any chars received (buffer can hold up to 32 chars!)
    if RXD then

        ' get next char into string
        get strText[nPos] 

        ' check for min length and end of string
        if (Len(strText) > 2) and (strText[nPos] = CR) then

            ' reset scan pos
            nPos = 0

            ' scan values in string
            do 
                ' Find pos of "=" 
                nPos = Pos(strText,"=",nPos) + 1 

                ' Nothing (more) found
                if nPos = 0 exit

                ' Parse value 
                print strText[nPos - 2],"=",Val(strText,nPos) 
            loop

            ' empty string 
            strText[0] = 0

        ' skip spaces 
        elsif strText[nPos] <> " " then 
            inc nPos 
        endif 
    endif

    ' just blink a led (access port pin)
    Port2.0 = not Port2.0

    ' slow down 
    pause 100
loop

 

 Control stepper motors...

' Hardware
#target TINYDISPLAY

' SetDisplay <Type: 0..4>
setdisplay
LCD_DOGM128x64               ' graphic display

' SetStepper <Motor: 0..2>,<Mode: 0=start/stop>
setstepper
0,0                          ' stepper 0 (start/stop)
setstepper 1,0                          ' stepper 1 (start/stop)
setstepper 2,0                          ' stepper 2 (start/stop) 

' The main loop
do

    stepper0.speed =  
250               ' speed in Hz
    stepper0.steps =
1000               ' steps to go
 
    stepper1.speed =  
400               ' speed
    stepper1.steps =
1000               ' steps         

    while Stepper0.Steps or Stepper1.Steps
        
gosub ShowPos
    
wend

    pause 2000

    stepper0.speed =   400              ' speed
    stepper0.steps = -
1000              ' step reverse

    stepper1.speed =   250              ' speed
    stepper1.steps = -
1000              ' step reverse

    while Stepper0.Steps or Stepper1.Steps
        
gosub ShowPos
    
wend

    pause 2000
loop        

' Show motor positions on display 
ShowPos:
    
move 0,0
    
print #2,"Job = ",Stepper0.Steps,"    "
    
print #2,"Pos = ",Stepper0,"       "
    
print #2," "
    
print #2,"Job = ",Stepper1.Steps,"    "
    
print #2,"Pos = ",Stepper1,"       "
    
print #2," "
    
print #2,"Job = ",Stepper2.Steps,"    "
    
print #2,"Pos = ",Stepper2,"       "
return

 

 Sending and receiving SMS...

' Hardware
#target TINYDISPLAY

' SetDisplay <Type: 0..4>
setdisplay
LCD_DOGM128x64               ' graphic display

' SetCom <Com: 0..1>,<Baud:300..115000>

setcom
0,9600                           ' default baudrate

' Variables

char
phone[20],text[300]

Init:
    
cls
    
print #2,"Init ",
    
initgsm 9824                        ' init modem (pin number)
    
if Err then print #2,"Err=",Err : pause 2000 : goto Init
    
print "ok!"  

Receive:        
    
cls
    
print #2,"Receive ",        
    
recvsms phone,text                  ' receive message from modem
    
if Err then print #2,"Err=",Err : pause 2000 : goto Receive
    
if len(phone) = 0 then print #2,".." : pause 100 : goto Receive  

    
cls
    
print #2,phone                      ' phone number of sender
    
print #2,text                       ' received message text

    
pause 5000                          ' time to read...

    
cls
    
print #2,"Send ",                   ' send message back   
    
sendsms phone,"Msg:",CR,text,CR,using("T = ##.##C",27.3)

    if Err then
        
print #2,"Err=",Err
    
else
        
print #2,"ok!"
    
endif

    
pause 2000                          ' time to read...

goto Receive