Microsoft Small Basic

Program Listing: GZN399-0
' OSOYOO UNO R3 - Temperature Sensor
' Version 0.2
' Copyright © 2016 Nonki Takahashi. The MIT License.
' Program ID GZN399-0

GraphicsWindow.Title = "Temperature Sensor"
Init()
InitBreadboard()
Draw()
DrawBreadboardHoles()
InitBoard()
Draw()
InitTMP36()
Draw()
param = "points=111.5 67 111.5 75;pw=1;pc=Red;"
DrawWire()
param = "points=108.5 75 95 75 95 85 56.5 85 56.5 75;pw=1;pc=Red;"
DrawWire()
param = "points=117.5 67 117.5 72.5;pw=1;pc=Black;"
DrawWire()
param = "points=108.5 72.5 93 72.5 93 83 59 83 59 75;pw=1;pc=Black;"
DrawWire()
param = "points=114.5 64.4 91 64.4 91 81 81 81 81 75;pw=1;pc=Yellow;"
DrawWire()

Sub Draw
GraphicsWindow.FontName = "OCRB"
GraphicsWindow.FontSize = 8
GraphicsWindow.FontBold = "False"
n = Array.GetItemCount(shape)
For i = 1 To n
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
GraphicsWindow.FillRectangle(x, y, width, height)
DrawHoles()
ElseIf shp["func"] = "ell" Then
GraphicsWindow.FillEllipse(x, y, width, height)
ElseIf shp["func"] = "line" Then
GraphicsWindow.PenColor = shp["pc"]
GraphicsWindow.PenWidth = shp["pw"] * scale
x1 = (ox + shp["x1"]) * scale
y1 = (oy + shp["y1"]) * scale
x2 = (ox + shp["x2"]) * scale
y2 = (oy + shp["y2"]) * scale
GraphicsWindow.DrawLine(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
GraphicsWindow.FillTriangle(x1, y1, x2, y2, x3, y3)
ElseIf shp["func"] = "text" Then
txt = shp["text"]
GraphicsWindow.FontName = shp["fn"]
GraphicsWindow.FontSize = shp["fs"] * scale
GraphicsWindow.FontItalic = shp["fi"]
GraphicsWindow.DrawText(x, y, txt)
EndIf
EndFor
EndSub

Sub DrawBreadboardHoles
GraphicsWindow.BrushColor = "Black"
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 63
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 Not[skip] Then
x = (ox + 3) * scale + (col - 1) * dx
GraphicsWindow.FillRectangle(x, y, width, height)
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"
GraphicsWindow.FillRectangle(hx, hy, hw, hh)
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
points = param["points"]
len = Text.GetLength(points)
n = 0
While p <= len
sp = Text.GetIndexOf(Text.GetSubTextToEnd(points, p), " ")
If 0 < sp Then
n = n + 1
x[n] = Text.GetSubText(points, p, sp - 1) * scale
p = p + sp
Else
x[n] = Text.GetSubTextToEnd(points, p) * scale
p = len + 1
EndIf
If p <= len Then
sp = Text.GetIndexOf(Text.GetSubTextToEnd(points, p), " ")
If 0 < sp Then
y[n] = Text.GetSubText(points, p, sp - 1) * scale
p = p + sp
Else
y[n] = Text.GetSubTextToEnd(points, p) * scale
p = len + 1
EndIf
EndIf
EndWhile
GraphicsWindow.FillEllipse(x[1] - size / 2, y[1] - size / 2, size, size)
For i = 2 To n
GraphicsWindow.DrawLine(x[i - 1], y[i - 1], x[i], y[i])
GraphicsWindow.FillEllipse(x[i] - size / 2, y[i] - size / 2, size, size)
EndFor
EndSub

Sub Init
Not = "False=True;True=False;"
gw = 598
gh = 428
GraphicsWindow.Width = gw
GraphicsWindow.Height = gh
url = Program.Directory + "\IMG_0045.JPG"
url = ""
img = ImageList.LoadImage(url)
iw = ImageList.GetWidthOfImage(img)
ih = ImageList.GetHeightOfImage(img)
x = 0
y = 0
scale = 0.135
width = iw * scale
height = ih * scale
photo = Shapes.AddImage(img)
Shapes.Move(photo, x - iw / 2 + width / 2, y - ih / 2 + height / 2)
Shapes.Zoom(photo, scale, scale)
Shapes.SetOpacity(photo, 50)
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=OSOYOO;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

Sub InitTMP36
scale = 4
ox = 112.3
oy = 38.5
shape = ""
shape[1] = "func=ell;x=0.5;y=4;width=4;height=4;bc=#333333;"
shape[2] = "func=rect;x=0.5;y=6;width=4;height=4;bc=Black;"
shape[3] = "func=line;x1=0.5;y1=10;x2=0;y2=12;pc=Silver;pw=0.5;"
shape[4] = "func=line;x1=0;y1=12;x2=0;y2=17;pc=Silver;pw=0.5;"
shape[5] = "func=line;x1=2.5;y1=10;x2=2.5;y2=17;pc=Silver;pw=0.5;"
shape[6] = "func=line;x1=4.5;y1=10;x2=5;y2=12;pc=Silver;pw=0.5;"
shape[7] = "func=line;x1=5;y1=12;x2=5;y2=17;pc=Silver;pw=0.5;"
EndSub