Sub Process_Globals
Public Serial1 As Serial
Private master As WireMaster
Private PortState(2) As Byte
End Sub
Private Sub AppStart
Serial1.Initialize(115200)
Log("AppStart")
master.Initialize
master.WriteTo(0x20, Array As Byte(0, 0)) 'A output
master.WriteTo(0x20, Array As Byte(1, 0xFF)) 'B input
Dim b As Byte = DigitalRead(1)
If Bit.Get(b, 5) = 1 Then
'''
End If
End Sub
'PortIndex - 0 = Port A, 1 = Port B
Private Sub DigitalRead (PortIndex As Byte) As Byte
master.WriteTo(0x20, Array As Byte(0x12 + PortIndex))
Dim result() As Byte = master.RequestFrom(0x20, 1)
If result.Length = 0 Then
Return 0
Else
Return result(0)
End If
End Sub
'PortIndex - 0 = Port A, 1 = Port B
Private Sub DigitalWrite (PortIndex As Byte, PinNumber As Byte, Value As Boolean)
If Value Then
PortState(PortIndex) = Bit.Set(PortState(PortIndex), PinNumber)
Else
PortState(PortIndex) = Bit.Clear(PortState(PortIndex), PinNumber)
End If
master.WriteTo(0x20, Array As Byte(0x12 + PortIndex, PortState(PortIndex)))
End Sub