Sub Process_Globals
Public Serial1 As Serial
Private astream As AsyncStreams
Private lcd As LiquidCrystal
Private pin0 As Pin
'These are the analog values that identify the LCD shield buttons.
Private btnValues() As UInt = Array As UInt(50, 250, 450, 650, 850)
Private const RIGHT = 0, UP = 1, DOWN = 2, LEFT = 3, SELECT_BTN = 4, NONE = 5 As Byte 'ignore
Private lastValue As Byte = NONE
End Sub
Private Sub AppStart
'don't use Log as it sends the data to the serial port
Serial1.Initialize(115200)
astream.Initialize(Serial1.Stream, "astream_NewData", "astream_Error")
lcd.Initialize(8, 255, 9, Array As Byte (4, 5, 6, 7))
lcd.Begin(16, 2)
lcd.Write("waiting for data")
pin0.Initialize(0, pin0.MODE_INPUT)
'CheckButton will be called repeatedly as fast as possible.
AddLooper("CheckButton")
'Send the first request to the RPi.
astream.Write(Array As Byte(0, SELECT_BTN))
End Sub
Sub CheckButton
'reading the buttons of the LCD keypad shield
Dim reading As UInt = pin0.AnalogRead
For i = 0 To btnValues.Length - 1
If reading < btnValues(i) Then Exit
Next
If i <> lastValue Then
lastValue = i
astream.Write(Array As Byte(0, i))
End If
End Sub
Sub AStream_NewData (Buffer() As Byte)
lcd.Clear
If Buffer.Length <> 7 Then
lcd.Write("error")
Return
End If
Dim raf As RandomAccessFile
raf.Initialize(Buffer, True)
lcd.Write(raf.ReadBytes2(3, raf.CurrentPosition)) '3 letters currency
lcd.SetCursor(0, 1)
lcd.Write(raf.ReadDouble32(raf.CurrentPosition))
End Sub
Sub AStream_Error
End Sub