概要
smallbasicでarduino unoを使ってosilloscopeを作った。
写真
サンプルコード1
yCenter = 300
y = 0
x = 0
SetupWindow()
InitVariables()
Class1.OpenPort("COM5", 9600)
Loop:
Cur = Class1.RXByte()
x = x + 1
If x > 800 Then
x = 0
endif
y = 400 - Cur
Shapes.Move(Dot[x], x, y)
Goto Loop
Sub SetupWindow
GraphicsWindow.Width = 800
GraphicsWindow.Height = 600
GraphicsWindow.BackgroundColor = "Black"
GraphicsWindow.Title = "Osilloscope"
GraphicsWindow.Show()
EndSub
Sub InitVariables
GraphicsWindow.PenColor = "orange"
GraphicsWindow.BrushColor = "orange"
For x = 0 To 800 Step 2
Dot[x] = Shapes.AddEllipse(4, 4)
Shapes.Move(Dot[x], x, yCenter)
EndFor
EndSub
サンプルコード2
void setup()
{
Serial.begin(9600);
}
void loop()
{
int val = analogRead(A0);
Serial.write((val >> 8) & 0xff);
}