Microsoft Small Basic

Program Listing:
Embed this in your website

GraphicsWindow.BrushColor="darkblue
tb=Controls.AddMultiLineTextBox (800,10)
Controls.ButtonClicked=bcc
ct="out 10 127|out 11 127|out 12 255|delay 500||out 10 199|out 11 199|out 12 199|delay 500||
ct=ct+"out 5 127|out 6 255|out 7 255|delay 500||out 5 199|out 6 199|out 7 199|delay 500||
ct=ct+"out 1 127|out 2 255|out 3 127|delay 500||out 1 199|out 2 199|out 3 199|delay 500||
nl=Text.GetCharacter (13)+Text.GetCharacter(10)
tt=ldtext.Replace (ct "|" nl)
Controls.SetTextBoxText (tb tt)
Controls.AddButton ("Run" 10 10)
Controls.SetSize (tb 200 500)
GraphicsWindow.BackgroundColor="teal
GraphicsWindow.Title = "Arduino led playground

   RLED_ON=ImageList.LoadImage("https://social.msdn.microsoft.com/Forums/getfile/863320")
   RLED_OFF=ImageList.LoadImage("https://social.msdn.microsoft.com/Forums/getfile/863319")
   BLED_OFF= ImageList.LoadImage("https://social.msdn.microsoft.com/Forums/getfile/952594")
   BLED_ON= ImageList.LoadImage("https://social.msdn.microsoft.com/Forums/getfile/952595")
   GLED_OFF= ImageList.LoadImage("https://social.msdn.microsoft.com/Forums/getfile/952596")
   GLED_ON= ImageList.LoadImage("https://social.msdn.microsoft.com/Forums/getfile/952597")



Init()
InitBreadboard()
Draw()
DrawBreadboardHoles()
InitBoard()
Draw()

orx=0
Initled()
Draw()
'lsh=ee

orx=4*2.5*scale +4
Initled()
Draw()
'lsh1=ee

orx=8*2.5*scale +8
Initled()
Draw()
'lsh2=ee

Sub bcc
  run="true
EndSub


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

orx=6*2.5*scale
param = "points=49 20 49 26;pw=1;pc=red
DrawWire()
param = "points=51.5 20 51.5 26;pw=1;pc=lime
DrawWire()
param = "points=54 20 54 26;pw=1;pc=blue
DrawWire()

orx=10*2.5*scale
param = "points=49 20 49 26;pw=1;pc=red
DrawWire()
param = "points=51.5 20 51.5 26;pw=1;pc=lime
DrawWire()
param = "points=54 20 54 26;pw=1;pc=blue
DrawWire()


orx=0
param = "points=116.5 62 93 62 93 20 49 20 49 26;pw=1;pc=red;"
DrawWire()

param = "points=114 64.5 93 64.5 93 20 51.5 20 51.5 26;pw=1;pc=lime;"
DrawWire()

param = "points=111.5 67 93 67 93 20 54 20 54 26;pw=1;pc=blue;"
DrawWire()

GraphicsWindow.DrawImage( RLED_OFF,446,155 )
GRAPhicsWindow.DrawImage( BLED_OFF,490,155 )
GraphicsWindow.DrawImage( GLED_OFF,535,155 )

GraphicsWindow.Width =1000
run="false

While "true
  If run Then
    GraphicsWindow.title=">>>>
    While "true
      tx= Controls.GetTextBoxText(tb)
      tl=ldtext.Split (tx nl)
      For x=1 To Array.GetItemCount (tl)
        cl=ldtext.Split (tl[x] " ")
        If cl[1]="delay" Then
          Program.Delay (cl[2])
        ElseIf cl[1]="out" then
        clr[cl[2]]=cl[3]
          scl=GraphicsWindow.GetColorFromRGB (clr[12] clr[11] clr[10])
          'GraphicsWindow.Title=clr[12]
          ' LDShapes.BrushColour (lsh scl)
          GraphicsWindow.DrawImage( RLED_ON,446,155 )
          Program.delay(Math.GetRandomNumber(100))
          GraphicsWindow.DrawImage( RLED_OFF,446,155 )
           scl=GraphicsWindow.GetColorFromRGB (clr[3] clr[2] clr[1])
           ' LDShapes.BrushColour (lsh1 scl)

          GraphicsWindow.DrawImage( BLED_ON,490,155 )
         Program.delay(Math.GetRandomNumber(500))
          GraphicsWindow.DrawImage( BLED_OFF,490,155 )
          scl=GraphicsWindow.GetColorFromRGB (clr[7] clr[6] clr[5])
         ' LDShapes.BrushColour (lsh2 scl)
         GraphicsWindow.DrawImage( GLED_ON,535,155 )
        Program.delay(Math.GetRandomNumber(800))
          GraphicsWindow.DrawImage( GLED_OFF,535,155 )

        EndIf
      EndFor
    EndWhile

  endif
  Program.Delay (2)
endwhile

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+orx, y, width, height)
      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
      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
  ps = ldtext.Split (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
    GraphicsWindow.DrawLine(ps[i - 2]*scale+orx , ps[i - 1]*scale, ps[i]*scale+orx, ps[i+1]*scale)
    GraphicsWindow.FillEllipse(ps[i]*scale - size / 2+orx, ps[i+1]*scale - size / 2, size, size)
  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

Sub Initled
  scale = 4
  ox = 112.3
  oy = 38.5
  shape = ""
  shape[1] = "func=rect;x=0;y=0;width=5;height=7;bc=Silver;"
  shape[2] = "func=ell;x=1;y=1;width=3;height=5;bc=Black;"
  shape[3] = "func=line;x1=0;y1=7;x2=0;y2=17;pc=Silver;pw=0.5;"
  shape[4] = "func=line;x1=2.5;y1=7;x2=2.5;y2=17;pc=Silver;pw=0.5;"
  shape[5] = "func=line;x1=5;y1=7;x2=5;y2=17;pc=Silver;pw=0.5;"
EndSub
Copyright (c) Microsoft Corporation. All rights reserved.