Sub Process_Globals
Public Serial1 As Serial
Private astream As AsyncStreams
Private led13 As Pin
Private btn As Pin
Private softserial As SoftwareSerial
End Sub
Private Sub AppStart
Serial1.Initialize(115200)
Log("appstart")
led13.Initialize(13, led13.MODE_OUTPUT)
led13.DigitalWrite(False)
softserial.Initialize(57600, 10, 11)
astream.Initialize(softserial.Stream, "astream_newdata", Null)
btn.Initialize(btn.A0, btn.MODE_INPUT_PULLUP)
btn.AddListener("Btn_StateChanged")
End Sub
Sub Btn_StateChanged (State As Boolean)
Dim b As Byte
If State Then b = 1 Else b = 0
astream.Write(Array As Byte(b))
End Sub
Sub astream_NewData (Buffer() As Byte)
Dim state As Boolean = Buffer(0) = 1 'state will be true if buffer(0) is 1.
led13.DigitalWrite(Not(state))
End Sub