LB Booster
Programming >> BASIC code examples >> Graphics sketch: Attiny connection to Arduino
http://lbb.conforums.com/index.cgi?board=code&action=display&num=1458270331

Graphics sketch: Attiny connection to Arduino
Post by michael on Mar 18th, 2016, 03:05am

As per conversation.. Run this in your LBB
and think about the idea.. Only you know what I am getting at..

Description: The code only drawn sketch and instructions for Attiny85 chip connection to Arduino..

I made a special IDE that runs in LBB for making graphics draws like this easily.
Code:

global hpos ' the horizontal locators for ENTER sub
global vpos ' the vertical locator for ENTER sub
global gcolor$   ' YOU MUST DEFINE gcolor$ BEFORE you use GRPRINT or ENTER but it only needs to be done once
call screen ' I made this for a generic screen call
hpos= 10         'lets give a starting location
vpos =500
gcolor$= "white" ' lets give a default color

'********x***y** h***v  -  original rectangle command had r,g,b numbers
call rect 100,100,200,200
call rect 90,100,100,110' Attiny legs
gcolor$="white"
call grprint 10,105,"leg 5   pin 0"
call rect 90,130,100,140
call grprint 10,140,"leg 6   pin 1"
call rect 90,160,100,160
call grprint 10,170,"leg 7   pin 2"
call rect 90,190,100,200
call grprint 10,201,"leg 8   5V"
call rect 200,100,210,110
call rect 200,130,210,140
call grprint 211,105,"leg 4    GND"
call rect 200,160,210,170
call grprint 211,140,"leg 3   pin 3"
call grprint 211,170,"leg 2   pin 4"
call grprint 211,200,"leg 1   "
call rect 200,190,210,200 'Attiny Legs ends
call circle 180,190, 5
gcolor$="green"
call rect 510,10,800,400
gcolor$="white"
for x=0 to 18
d=d+20
call circle 515,d,2
call circle 795,d,2
next x
gcolor$="white"
call grprint 500,25,"1"
call grprint 500,45,"2"
call grprint 500,65,"3"
call grprint 500,85,"4"
call grprint 500,105,"5"
call grprint 500,125,"6"
call grprint 500,145,"7"
call grprint 500,165,"8"
call grprint 500,185,"9"
gcolor$="brown"
call grprint 805,185,"GND"
call grprint 805,205,"GND"
gcolor$="red"
call grprint 805,225,"5   Volt"
call grprint 805,245,"3.3 Volt"
gcolor$="white"
call grprint 805,265,"RESET"
      gcolor$="white"
call grprint 495,205,"10"
call grprint 495,225,"11"
call grprint 495,245,"12"
call grprint 495,265,"13"
gcolor$="brown"
call grprint 480,285,"GND"
gcolor$="white"
call enter "Connect Leg 4 to Arduino GND (ground)"
call enter "Connect Leg 1 to Arduino pin 10"
call enter "Connect Leg 5 to Arduino pin 11"
call enter "Connect Leg 6 to Arduino pin 12"
call enter "Connect Leg 7 to Arduino pin 13"
gcolor$="red"
call enter "Connect Leg 8 to Arduino 5 Volt"
call enter "Connect a 10uf 25volt capacitor between GND and RESET (make sure the stripe side is attached to GND!!!!)"
wait
[quit]
 #1 "discard"
 close #1
 end
sub enter message$
#1 "place ";hpos;" ";vpos
#1 "backcolor black"
#1 "color ";gcolor$
#1 "\";message$
vpos=vpos+20
end sub


sub gline x,y,h,v  ' its my attempt to bring back a line command. like in the old days
#1 "backcolor black"
#1 "color ";gcolor$
#1 "line ";x;" ";y;" ";h;" ";v
end sub

sub grprint x,y,message$
    #1 "backcolor black"
    #1 "up"
    #1 "place ";x;" ";y
    #1 "down"
    #1 "color ";gcolor$
    #1 "\";message$
    end sub

sub sphere h,v,size,x,c,a,dimmer ' dimmer cannot be more than 24
#1 "place ";h;" ";v
for y=1 to size
#1 "down"
#1 "color ";x;" ";c;" ";a
#1 "size 2"
#1 "circle ";y
#1 "flush"
x=x-dimmer
c=c-dimmer
a=a-dimmer
if x<2 then x=2
if c<2 then c=2
if a<2 then a=2
next y
end sub
'block h,v,size,R,G,B,dimmer
sub block h,v,size,x,c,a,dimmer ' dimmer cannot be more than 24
#1 "place ";h;" ";v
p=size/2
for y=1 to size
#1 "down"
#1 "color ";x;" ";c;" ";a
#1 "size 1"
print #1, "line ";h-y;" ";v-y;" ";h+y;" ";v-y
print #1, "line ";h+y;" ";v-y;" ";h+y;" ";v+y
print #1, "line ";h+y;" ";v+y;" ";h-y;" ";v+y
print #1, "line ";h-y;" ";v+y;" ";h-y;" ";v-y
x=x-dimmer
c=c-dimmer
a=a-dimmer
if x<2 then x=2
if c<2 then c=2
if a<2 then a=2
p=p-1
next y
end sub
'ellipse h,v,sizex,sizey,R,G,B,dimmer
sub ellipse h,v,sizex,sizey,x,c,a,dimmer ' dimmer cannot be more than 24
#1 "place ";h;" ";v
if sizex>sizey then limit=sizex
if sizey>sizex then limit=sizey
for y=1 to limit
#1 "down"
#1 "color ";x;" ";c;" ";a
#1 "size 2"
hi=hi+1:if sizex>sizey then hi=hi+1
wi=wi+1:if sizey>sizex then wi=wi+1
if hi>sizex then hi=sizex
if wi>sizey then wi=sizey
#1 "ellipse ";hi;" ";wi
x=x-dimmer
c=c-dimmer
a=a-dimmer
if x<2 then x=2
if c<2 then c=2
if a<2 then a=2
next y
end sub
'initialize generic screen
sub screen
   nomainwin
   open "My new way of doing graphics !!" for graphics_nsb_fs as #1
   print #1, "Down trapclose [quit]"

    print #1, "fill black ; home ; down ; north"
end sub
' generic circle   syntax -  circle horizontal, vertical, size, color$
sub circle x, y, size
   print #1," place  "; x;" ";y
   print #1," color "; gcolor$
   print #1," circle "; size
end sub

sub color c$
print #1, "color ";c$
end sub
'chip x,y,size, color$,topcolor$,midcolor$
sub chip x,y,size, color$ , topcolor$,midcolor$            '******** HERE IS THE CHIP SUB FOR THIS PROJECT
print #1, "down"
if size< 30 then size =30
print #1, "color ";color$
for nloc= 1 to size/10
print #1,"place "; x;" ";y-nloc
print #1, "ellipsefilled ";size;" ";size/2
next nloc
print #1, "flush"
print #1, "color ";topcolor$
print #1, "ellipsefilled ";size;" ";size/2
print #1, "flush"
print #1, "color ";midcolor$
m= size/4
print #1, "ellipsefilled ";size/2;" ";m
print #1, "flush"
end sub
' ****************** RATING STARS **************

sub star h, v, type$
    if type$ ="starhalf" then restore [starhalf]
    if type$ ="starfull" then restore [starfull]
    ost$ =""
    read x, y

    while nst$ <>"100000"
        read nst$, t
        if nst$ ="0" then r =  0: g=   0:  b=   0   'black         0   0   0
        if nst$ ="3" then r =128: g= 128:  b= 128   'dark grey   128 128 128
        if nst$ ="b" then r =224: g=  32:  b=  64   'light red   224  32  64
        if nst$ ="h" then r =255: g= 255:  b= 255   'white       255 255 255
        if nst$ ="i" then r =255: g= 255:  b=   0   'yellow      255 255   0
        #1 "color "; r; " "; g; " "; b
        for u =0 to t
            a =a +1
            #1 "set "; c +h; " "; a +v
            if a >x  then c =c +1: a =0
        next u
    wend
    #1 "flush"

  [starhalf]
    data 16,16
    data 0,5,b,0,0,15,b,1,0,14,b,0,h,0,b,0,0,13,b,0,i,0,b,0,0,4,b,1,0,6,b,0,i,1,b,0,0,0,b,3,0
    data 7,b,0,i,2,b,0,h,0,i,1,b,0,0,7,b,0,i,5,b,0,0,5,b,2,i,5,h,0,b,0,0,3,b,1,h,1,i,6,b,0
    data 100000,0

  [starfull]
    data 16,16
    data 0,5,b,0,0,15,b,1,0,14,b,0,h,0,b,0,0,13,b,0,i,0,b,0,0,4,b,1,0,6,b,0,i,1,b,0,0,0,b,3,0
    data 7,b,0,i,2,b,0,h,0,i,1,b,0,0,7,b,0,i,5,b,0,0,5,b,2,i,5,h,0,b,0,0,3,b,1,h,1,i,6,b,0
    data 0,6,b,2,h,0,i,5,b,0,0,8,b,0,i,2,h,1,i,0,b,0,0,8,b,0,i,1,h,0,b,0,h,2,b,0,0,7,b,0,i
    data 0,h,0,b,0,0,0,b,3,0,7,b,0,h,0,b,0,0,4,b,1,0,6,b,0,h,0,b,0,0,13,b,1,100000,0

end sub
sub triangle h,v,size,NESW$,x,c,a,dimmer,direction$ ' dimmer cannot be more than 24
#1 "place ";h;" ";v
p=size/2
if direction$="top" then rev=0
if direction$="bottom" then rev=size
for y=1 to size
if direction$="top" then rev=rev+1
if direction$="bottom" then rev=rev-1
#1 "down"
#1 "color ";x;" ";c;" ";a
#1 "size 1"
if NESW$="south" then print #1, "line ";h-rev;" ";v-rev;" ";h+rev;" ";v-rev
if NESW$="west" then print #1, "line ";h+rev;" ";v-rev;" ";h+rev;" ";v+rev
if NESW$="north" then print #1, "line ";h+rev;" ";v+rev;" ";h-rev;" ";v+rev
if NESW$="east" then print #1, "line ";h-rev;" ";v+rev;" ";h-rev;" ";v-rev
x=x-dimmer
c=c-dimmer
a=a-dimmer
if x<2 then x=2
if c<2 then c=2
if a<2 then a=2
p=p-1
next y
end sub
sub userdef3D x,y,h,v,h1,v1,x1,y1,r,g,b,size' dimmer cannot be more than 24
#1 "down"
r2=r : g2=g : b2=b
for up =1 to size
#1 "color ";r2;" ";g2;" ";b2
print #1, "line ";x;" ";y+up;" ";h;" ";v+up
r2=r2-1
g2=g2-1
b2=b2-1
next up
r1=r : g1=g : b1=b
for up =1 to size
#1 "color ";r1;" ";g1;" ";b1
if h1>h then print #1, "line ";h;" ";v+up;" ";h1;" ";v1+up'right side
if h1<h then print #1, "line ";x1;" ";y1+up;" ";x;" ";y+up'left side
r1=r1-1
g1=g1-1
b1=b1-1
next up
r1=r : g1=g : b1=b
for up =1 to size
#1 "color ";r;" ";g;" ";b
if h1<h then print #1, "line ";h;" ";v+up;" ";h1;" ";v1+up'right side
if h1>h then print #1, "line ";x1;" ";y1+up;" ";x;" ";y+up'left side
r=r-1
g=g-1
b=b-1
next up
for up =1 to size
#1 "color ";r1;" ";g1;" ";b1
print #1, "line ";h1;" ";v1+up;" ";x1;" ";y1+up

r1=r1-1
g1=g1-1
b1=b1-1
next up
end sub

sub rect x,y,h,v
#1 "down"
#1 "color ";gcolor$
#1 "size 1"
print #1, "line ";x;" ";y;" ";h;" ";y
print #1, "line ";h;" ";y;" ";h;" ";v
print #1, "line ";h;" ";v;" ";x;" ";v
print #1, "line ";x;" ";v;" ";x;" ";y
end sub

sub panel h,v,size,size2,NESW$,x,c,a,dimmer,direction$ ' dimmer cannot be more than 24
p=size/2
if direction$="top" then rev=size2
if direction$="bottom" then rev=size
for y=size2 to size
if direction$="top" then rev=rev+1
if direction$="bottom" then rev=rev-1
#1 "down"
#1 "color ";x;" ";c;" ";a
#1 "size 1"
if NESW$="south" then print #1, "line ";h-rev;" ";v-rev;" ";h+rev;" ";v-rev
if NESW$="west" then print #1, "line ";h+rev;" ";v-rev;" ";h+rev;" ";v+rev
if NESW$="north" then print #1, "line ";h+rev;" ";v+rev;" ";h-rev;" ";v+rev
if NESW$="east" then print #1, "line ";h-rev;" ";v+rev;" ";h-rev;" ";v-rev
x=x-dimmer
c=c-dimmer
a=a-dimmer
if x<2 then x=2
if c<2 then c=2
if a<2 then a=2
p=p-1
next y
end sub

 
 

Re: Graphics sketch: Attiny connection to Arduino
Post by michael on Mar 18th, 2016, 03:11am

TOOL:

http://lbb.conforums.com/index.cgi?board=general&action=display&num=1455642056

Use UP/DOWN arrows to scroll through program (click in area first)
(make sure you also make a COLOR and type DOWN at start or it wont draw)
*<ENTER> runs stored code and refreshes screen
* The ADD button adds a line or circle or rectangle you make
* LEFT / RIGHT mouse buttons for draws
*Autoruns
*Make sure you have it on an empty line when you ADD