Microsoft Small Basic

Program Listing: LBQ108
GraphicsWindow.BrushColor="darkblue
tb=Controls.AddMultiLineTextBox (800,10)
'Controls.ButtonClicked=bcc
ct=" #include ||VGAX vga;||void setup() {| vga.begin();| vga.clear(11);| for (int y=0; y!=VGAX_HEIGHT; y++) {| for (int x=0; x!=VGAX_BWIDTH; x++) {| vga.putpixel4(x, y, y%2 ? 27 : 228);| }| }|}|void loop() {|}
ct=ct+"||resistors:| R1 = R4 = 68 Ω | R2 = R3 = 470 Ω
nl=Text.GetCharacter (13)+Text.GetCharacter(10)
tt=ldtext.Replace (ct "|" nl)
Controls.SetTextBoxText (tb tt)
'Controls.AddButton ("Run" 10 10)
Controls.SetSize (tb 300 600)
GraphicsWindow.BackgroundColor="teal
GraphicsWindow.Title = "Arduino VGA
Init()
InitBreadboard()
Draw()
DrawBreadboardHoles()
InitBoard()
Draw()


orx =0
param = "points=108.5 72.5 93 72.5 93 83 59 83 59 75;pw=1;pc=Black
DrawWire()

orx =550
param = "points= -20 15 0 15 0 72.5 ;pw=1;pc=Black
DrawWire()
args=0

Sub drawrr '----------------------------draws resistance
orx =args[1]
ox=-2
param = "points= 0:"+ (22+args[2])+":0:"+(35+args[2])+";pw=1;pc=gold
DrawWire()
shape=""
shape[1] = "func=rect;x=0;y="+args[2]+";width=4;height=9;bc=gold
shape[2] = "func=text;x=0;y="+(args[2]+2)+";text=R"+args[3]+";fn=Arial;fs=4.2;bc=black

Draw()
Shapes.Rotate(txt, -90)
EndSub

For q=0 to 3
LDCall.Function3("drawrr" 437+q*22 21 q+1)
endfor

ox=10
orx=6*2.5*scale

param = "points=59 26 59 22 72 22 72 66.5 94 66.5;pw=1;pc=cyan
DrawWire()
param = "points=51.5 26 51.5 20 73.5 20 73.5 64.5 99.5 64.5;pw=1;pc=orange
DrawWire()
param = "points=49 26 49 18 75 18 75 62.5 105 62.5;pw=1;pc=lime
DrawWire()
param = "points=42.5 26 42.5 16 76.5 16 76.5 60.5 110.5 60.5;pw=1;pc=magenta
DrawWire()

param = "points=94 35.5 93.5 22.5;pw=1;pc=cyan
DrawWire()
param = "points=110.5 35.5 97 22.5;pw=1;pc=magenta
DrawWire()
param = "points=105 42 120 42 120 6 89 6 89 9 ;pw=1;pc=lime
DrawWire()
param = "points=99.5 39 118 39 118 3 86 3 86 9 ;pw=1;pc=orange
DrawWire()

GraphicsWindow.Width =1100
run="false
LDShapes.ZIndex (tb 1000)
LDEvents.MouseWheel=mww
GraphicsWindow.MouseMove=mmv
GraphicsWindow.MouseDown=mdd

Sub mww
If GraphicsWindow.LastKey="Space" Then
zr=zr+LDEvents.LastMouseWheelDelta*5
else
zz=zz+ LDEvents.LastMouseWheelDelta /10

If zz>2 Then
zz=2
ElseIf zz<.5 then
zz=.5
EndIf
GraphicsWindow.Title =zz
endif
LDGraphicsWindow.Reposition (zz zz 100 200 zr)
EndSub

Sub mdd

sx= GraphicsWindow.MouseX
sy= GraphicsWindow.MouseY
EndSub

Sub mmv
If Mouse.IsLeftButtonDown Then
ddx= GraphicsWindow.MouseX -sx
ddy= GraphicsWindow.MouseY - sy
gw= GraphicsWindow.Width
gh= GraphicsWindow.Height
gwX = (ddx+wx)*zz + gw*(1-zz)/2
gwY = (ddy+wy)*zz + gh*(1-zz)/2
wx=wx+ddx
wy=wy+ddy
LDGraphicsWindow.Reposition (zz zz gwx gwy zr)
endif
endsub

For r=0 to 4
GraphicsWindow.PenWidth=0
If r=0 Then
GraphicsWindow.BrushColor="red
ElseIf r=1 then
GraphicsWindow.BrushColor="lime
ElseIf r=2 then
GraphicsWindow.BrushColor="blue
ElseIf r=4 then
GraphicsWindow.BrushColor="black
else
GraphicsWindow.BrushColor="lightgray
endif
shapes.Move(Shapes.AddEllipse (5 5) r*15+400 40)
endfor

For r=0 to 4
GraphicsWindow.PenWidth=0
If r=3 Then
GraphicsWindow.BrushColor="lightgray
Else
GraphicsWindow.BrushColor="black
endif
shapes.Move(Shapes.AddEllipse (5 5) r*15+393 60)
endfor

For r=0 to 4

If r=2 Then
GraphicsWindow.BrushColor="cyan
ElseIf r=3 then
GraphicsWindow.BrushColor="magenta
else
GraphicsWindow.BrushColor="lightgray
endif
shapes.Move(Shapes.AddEllipse (5 5) r*15+400 80)
endfor
shape=""
shape[1] = "func=text;x=380;y=30;text=1 5;fn=Courier New;fs=4;bc=white
shape[2] = "func=text;x=375;y=75;text=11 15;fn=Courier New;fs=4;bc=white

Drawtx()

While "true

Program.Delay (2)
endwhile

Sub Drawtx
n = Array.GetItemCount(shape)
For i = 1 To n
shp = shape[i]
x = shp["x"]
y = shp["y"]
txt = shp["text"]
GraphicsWindow.FontName = shp["fn"]
GraphicsWindow.FontSize = shp["fs"] * scale
GraphicsWindow.FontItalic = shp["fi"]
shapes.Move(shapes.addText( txt) x, y)

EndFor
endsub

Sub Draw
GraphicsWindow.FontName = "OCRB"
GraphicsWindow.FontSize = 8
GraphicsWindow.FontBold = "False"
n = Array.GetItemCount(shape)
For i = 1 To n
GraphicsWindow.PenWidth =0
shp = shape[i]
x = (ox + shp["x"]) * scale
y = (oy + shp["y"]) * scale
width = shp["width"] * scale
height = shp["height"] * scale
GraphicsWindow.BrushColor = shp["bc"]

If shp["func"] = "rect" Then
shapes.Move(shapes.AddRectangle ( width, height) x+orx, y)
DrawHoles()

ElseIf shp["func"] = "ell" Then
GraphicsWindow.PenWidth=-0
ee=Shapes.AddEllipse(width, height)
Controls.Move (ee x+orx y)

ElseIf shp["func"] = "line" Then
GraphicsWindow.PenColor = shp["pc"]
GraphicsWindow.PenWidth = shp["pw"] * scale
x1 = (ox + shp["x1"]) * scale+orx
y1 = (oy + shp["y1"]) * scale
x2 = (ox + shp["x2"]) * scale+orx
y2 = (oy + shp["y2"]) * scale
shapes.addLine(x1, y1, x2, y2)

ElseIf shp["func"] = "tri" Then
x1 = (ox + shp["x1"]) * scale
y1 = (oy + shp["y1"]) * scale
x2 = (ox + shp["x2"]) * scale
y2 = (oy + shp["y2"]) * scale
x3 = (ox + shp["x3"]) * scale
y3 = (oy + shp["y3"]) * scale
shapes.addTriangle(x1, y1, x2, y2, x3, y3)

ElseIf shp["func"] = "text" Then
tx = shp["text"]
GraphicsWindow.FontName = shp["fn"]
GraphicsWindow.FontSize = shp["fs"] * scale
GraphicsWindow.FontItalic = shp["fi"]
txt=shapes.addText( tx)
shapes.Move(txt x+orx-2, y)
EndIf
EndFor
EndSub

Sub DrawBreadboardHoles
GraphicsWindow.PenWidth =0
GraphicsWindow.BrushColor = "brown
size = 1
width = size * scale
height = size * scale
dx = 2.8 * scale
dy = 2.8 * scale
For row = 1 To 18
y = (oy + 3) * scale + (row - 1) * dy
If row = 3 Or row = 9 Or row = 10 Or row = 16 Then
Else
For col = 1 To 43
If row = 1 Or row = 2 Or row = 17 Or row = 18 Then
If 3 <= col And col <= 61 And Math.Remainder(col, 6) <> 2 Then
skip = "False"
Else
skip = "True"
EndIf
Else
skip = "False"
EndIf
If skip Then
else
x = (ox + 3) * scale + (col - 1) * dx
shapes.Move(Shapes.AddRectangle ( width, height) x, y)
EndIf
EndFor
EndIf
EndFor
EndSub

Sub DrawHoles
If i = 11 Then
holes = 10
s = symbol[1]
ElseIf i = 12 Then
holes = 8
s = symbol[2]
ElseIf i = 13 Then
holes = 8
s = symbol[3]
ElseIf i = 14 Then
holes = 6
s = symbol[4]
Else
holes = 0
EndIf
If 0 < holes Then
x = (ox + shp["x"]) * scale
y = (oy + shp["y"]) * scale
width = shp["width"] * scale
height = shp["height"] * scale
hw = (width - (holes + 1) * 3) / holes
hy = y + 3
hh = height - 6
pin = 0
For hx = x + 3 To x + width - hw - 2 Step hw + 3
GraphicsWindow.BrushColor = "Black"
shapes.Move(Shapes.AddRectangle( hw, hh) hx, hy)
pin = pin + 1
GraphicsWindow.BrushColor = "White"
len = Text.GetLength(s[pin])
txt = Shapes.AddText(s[pin])
If i < 13 Then
Shapes.Move(txt, hx + (1.8 - len) * 2.8 - 2, hy + len * 2.4 + 8)
Else
Shapes.Move(txt, hx + (1.8 - len) * 2.8 - 2, hy - len * 2.4 - 10)
EndIf
Shapes.Rotate(txt, -90)
EndFor
EndIf
EndSub

Sub DrawWire
size = param["pw"] * scale
GraphicsWindow.PenWidth = size
GraphicsWindow.PenColor = param["pc"]
GraphicsWindow.BrushColor = param["pc"]
p = 1
ps = ldtext.Split (ldtext.Replace (param["points"] ":" " ") " ")

'GraphicsWindow.FillEllipse(ps[1]*scale - size / 2+orx, ps[2]*scale - size / 2, size, size)
For i = 3 To Array.GetItemCount (ps) Step 2
shapes.addLine(ps[i - 2]*scale+orx , ps[i - 1]*scale, ps[i]*scale+orx, ps[i+1]*scale)
el=shapes.AddEllipse ( size, size)
Shapes.Move(el ps[i]*scale - size / 2+orx, ps[i+1]*scale - size / 2)
EndFor
EndSub

Sub Init
Not = "False=True;True=False
gw = 500
gh = 500
GraphicsWindow.Width = gw
GraphicsWindow.Height = gh

x = 0
y = 0
scale = 0.135

EndSub

Sub InitBoard
scale = 4
ox = 10
oy = 24
shape = ""
shape[1] = "func=rect;x=7;y=0;width=65;height=53;bc=#003366
shape[2] = "func=tri;x1=72;y1=0;x2=72;y2=1;x3=73;y3=1;bc=#003366
shape[3] = "func=rect;x=72;y=1;width=1;height=52;bc=#003366
shape[4] = "func=tri;x1=73;y1=13;x2=73;y2=16;x3=76;y3=16;bc=#003366
shape[5] = "func=rect;x=73;y=16;width=3;height=32;bc=#003366
shape[6] = "func=tri;x1=73;y1=48;x2=73;y2=51;x3=76;y3=48;bc=#003366
shape[7] = "func=rect;x=0;y=9;width=16;height=12;bc=Silver
shape[8] = "func=rect;x=10;y=1;width=6;height=6;bc=Silver
shape[9] = "func=ell;x=11.75;y=2.75;width=2.5;height=2.5;bc=Red
shape[10] = "func=rect;x=5;y=40;width=14;height=9;bc=#333333
shape[11] = "func=rect;x=25;y=1;width=26;height=3;bc=#333333
shape[12] = "func=rect;x=52;y=1;width=21;height=3;bc=#333333
shape[13] = "func=rect;x=35;y=49;width=21;height=3;bc=#333333
shape[14] = "func=rect;x=57;y=49;width=16;height=3;bc=#333333
shape[15] = "func=rect;x=37;y=32;width=36;height=10;bc=#333333
shape[16] = "func=text;x=38;y=12;text=Arduino;fn=Impact;fs=4;fi=True;bc=White
shape[17] = "func=text;x=53.5;y=12;text=UNO;fn=Arial;fs=4.2;bc=White
shape[18] = "func=ell;x=21;y=1;width=3.2;height=3.2;bc=White
shape[19] = "func=ell;x=20;y=49;width=3.2;height=3.2;bc=White
shape[20] = "func=ell;x=71.5;y=16;width=3.2;height=3.2;bc=White
shape[21] = "func=ell;x=71.5;y=44;width=3.2;height=3.2;bc=White
symbol[1] = "3=AREF;4=GND;5=D13;6=D12;7=D11;8=D10;9=D9;10=D8
symbol[2] = "1=D7;2=D6;3=D5;4=D4;5=D3;6=D2;7=D1;8=D0
symbol[3] = "2=IOREF;3=RESET;4=3.3V;5=5V;6=GND;7=GND;8=Vin
symbol[4] = "1=A0;2=A1;3=A2;4=A3;5=A4;6=A5
EndSub

Sub InitBreadboard
scale = 4
ox = 100
oy = 24
shape = ""
shape[1] = "func=rect;x=0;y=0;width=166;height=54;bc=#F8FFCC
shape[2] = "func=rect;x=0;y=26;width=166;height=2;bc=#E8EEBB
shape[3] = "func=text;x=3;y=0;text=-;fn=Courier New;fs=4;bc=DodgerBlue
shape[4] = "func=rect;x=6;y=1;width=152;height=0.8;bc=DodgerBlue
shape[5] = "func=text;x=3;y=5;text=+;fn=Courier New;fs=4;bc=Red
shape[6] = "func=rect;x=6;y=7.6;width=152;height=0.8;bc=Red
shape[7] = "func=text;x=3;y=44.8;text=-;fn=Courier New;fs=4;bc=DodgerBlue
shape[8] = "func=rect;x=6;y=45.8;width=152;height=0.8;bc=DodgerBlue
shape[9] = "func=text;x=3;y=49.4;text=+;fn=Courier New;fs=4;bc=Red
shape[10] = "func=rect;x=6;y=52.2;width=152;height=0.8;bc=Red
EndSub