Sub AppStart (Args() As String)
Dim bus As JavaObject = GetBus(0)' Raspberry rev 1
Dim device As JavaObject = GetDevice(bus, 32)' all addressbits on the MCP23017 are high (0x20)
Dim i As Boolean
i= True
Dim buffer(20) As Byte ' see below
write2(device, Array As Byte(01,00),0,2) ' all bits on GPB (0x01) are output (0x00)
Do While i= True
Write2(device, Array As Byte(00, 8), 0, 2) ' GPIOA bit 3 set to INPUT. Try to set this command outside While loop.
' and debug buffer0 to buffer20. You see The state of these will shift.
Read2(device, buffer,0,20)' read first 20 bytes from several registers....setting offset to something else then 0 will result in java exception errors !
' in case of MCP23017 you need to ' read' register 0x12 for the inputstate of GPA0-GPA7
' it was/is not possible to only read the state of 0x12. Therefore I load 20 registers.
If buffer(17) = -9 Then ' I need register 18 (0x12) to read state of GPA. During debug I see that i need register 17....
' maybe because of offset. Well...It works.
' have to do something about the -9 though. :-)
Log (" SET")
Write2(device, Array As Byte(0x15,0x01),0,2)' output GPB0 high
Else
Write2( device,Array As Byte (0x15,0x00),0,2)' output GPB- low
End If
Loop ' endless loop
End Sub