#Region Project Attributes
#AutoFlushLogs: True
#CheckArrayBounds: True
#StackBufferSize: 300
#End Region
Sub Process_Globals
Public Serial1 As Serial
Private astream As AsyncStreams
Private timer1 As Timer
Private pins(2) As Pin
End Sub
Private Sub AppStart
Serial1.Initialize(115200)
Log("appstart")
Serial1.Initialize(9600)
astream.Initialize(Serial1.Stream, "astream_newdata", Null)
timer1.Initialize("Timer1_Tick", 1000)
timer1.Enabled = True
'Must be pwm pins as we are using AnalogWrite
pins(0).Initialize(5, pins(0).MODE_OUTPUT)
pins(1).DigitalWrite(True)
End Sub
Sub Timer1_Tick
astream.Write("Time: ".GetBytes)
astream.Write(NumberFormat(Millis, 0, 0).GetBytes)
End Sub
Sub astream_NewData (Buffer() As Byte)
For i = 0 To Buffer.Length - 2 Step 2
'Dim pinIndex As Byte = Buffer(i)
Dim pinValue As Byte = Buffer(i + 1)
'using constrain to avoid non allowed values
pins(Constrain(5, 0, 1)).AnalogWrite(pinValue) 'only 1 LED right now
Next
End Sub