I have to monitor 6 pins with switches on each pin. My question is what is the best way to do this.
Do I use a timer and pole with digitalread or do I use addlistener for each pin? What are the pros and cons using both methods
You should use AddListener. It is simpler to implement.
You can use the same sub event to handle all pins:
B4X:
pin1.AddListener("pin_StateChanged")
pin2.AddListener("pin_StateChanged")
pin3.AddListener("pin_StateChanged")
Sub Pin_StateChanged (State As Boolean)
Dim p As Pin = Sender
Log("Pin: ", p.PinNumber, ", state: ", State)
End Sub
It's possible to AddListener to analog value? State as Int?
I try
B4X:
SpeedMotor.Initialize(SpeedMotor.A0, SpeedMotor.MODE_INPUT)
SpeedMotor.AddListener("SpeedPotencjometr_StateChanged")
Sub SpeedPotencjometr_StateChanged(State As Int)
Log(State)
End Sub
but status is only 25600 or 25601.
How to properly initialize the pins?