Sub Process_Globals
Public Serial1 As Serial
Private SoftwareSerial1 As SoftwareSerial
Private astream As AsyncStreams
Private leds(1) As Pin
Private timer1 As Timer
End Sub
Private Sub AppStart
Serial1.Initialize(115200)
Log("AppStart")
leds(0).Initialize(leds(0).A0, leds(0).MODE_OUTPUT)
SoftwareSerial1.Initialize(9600, 10, 11) 'software serial port on pins 10 and 11
astream.Initialize(SoftwareSerial1.Stream, "astream_NewData", Null)
timer1.Initialize("timer1_Tick", 1000)
timer1.Enabled = True
End Sub
Sub Timer1_Tick
astream.Write("Millis here: ".GetBytes)
astream.Write(NumberFormat(Millis, 0, 0).GetBytes)
astream.Write(Array As Byte(10)) 'end of line character. AsyncStreamsText will cut the message here
End Sub
Sub AStream_NewData (Buffer() As Byte)
For i = 0 To Buffer.Length - 2 Step 2
Dim ledNumber As Byte = Buffer(i)
Dim value As Boolean = Buffer(i + 1) = 1
leds(ledNumber).DigitalWrite(value)
Next
End Sub