I'm trying to test the idea of reading sensor information based on resistors at https://learn.adafruit.com/basic-resistor-sensor-reading-on-raspberry-pi?view=all for use in B4J. That Python code works well on my circuit but I'm having problems with B4J.
How do you either have both an Output and Input type on the same Pin (you really can't do that) OR Switch rapidly between the two types?
Comment inline the code below giving the error. I've tried releasing the PinXo before initializing the PinXi and vice-versa but that doesn't work. Neither does controller.shutdown and re-initializing.
Any ideas?
How do you either have both an Output and Input type on the same Pin (you really can't do that) OR Switch rapidly between the two types?
Comment inline the code below giving the error. I've tried releasing the PinXo before initializing the PinXi and vice-versa but that doesn't work. Neither does controller.shutdown and re-initializing.
Any ideas?
B4X:
'Non-UI application (console application)
#Region Project Attributes
#CommandLineArgs:
#MergeLibraries: true
#End Region
Sub Process_Globals
Dim controller As GpioController
Dim PinXo As GpioPinDigitalOutput
Dim PinXi As GpioPinDigitalInput
Dim Reading As Int
Dim Timer1 As Timer
End Sub
Sub AppStart (Args() As String)
Reading = 0
controller.Initialize
PinXo.Initialize(27, False) ' Init the Output Pin and set the pin LOW (False)
' The following line give the error ...
' com.pi4j.io.gpio.exception.GpioPinExistsException: This GPIO pin already exists: GPIO 27
PinXi.Initialize("PinXi", 27) ' Init the Input Pin
Timer1.Initialize("Timer1",10) ' Check the value every 10 milliseconds
StartMessageLoop
End Sub
Sub PinXi_StateChange(State As Boolean)
If State = True Then
Timer1.Enabled = False
Log("Reading: " & Reading)
Reading = 0
PinXo.Blink(1) ' Set the pin LOW for 1 millisecond to reset the capacitor in order to start again
Timer1.Enabled = True
End If
Log("PinX StateChange event: " & State)
End Sub
Sub Timer1_Tick
Reading = Reading + 1
End Sub