W whcir Member Licensed User Longtime User Jul 19, 2016 #1 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 Thanks
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 Thanks
Erel B4X founder Staff member Licensed User Longtime User Jul 19, 2016 #2 You should use AddListener. It is simpler to implement. You can use the same sub event to handle all pins: Code: Copy 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 Upvote 0
You should use AddListener. It is simpler to implement. You can use the same sub event to handle all pins: Code: Copy 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
BaGRoS Active Member Licensed User Longtime User Apr 14, 2017 #3 It's possible to AddListener to analog value? State as Int? I try Code: Copy 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? Code: Copy SpeedMotor.Initialize(SpeedMotor.A0, SpeedMotor.MODE_INPUT) SpeedMotor.Initialize(0, SpeedMotor.MODE_INPUT) SpeedMotor.Initialize(SpeedMotor.A0, SpeedMotor.AnalogRead) SpeedMotor.Initialize(0, SpeedMotor.AnalogRead) Read from the potentiometer. Upvote 0
It's possible to AddListener to analog value? State as Int? I try Code: Copy 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? Code: Copy SpeedMotor.Initialize(SpeedMotor.A0, SpeedMotor.MODE_INPUT) SpeedMotor.Initialize(0, SpeedMotor.MODE_INPUT) SpeedMotor.Initialize(SpeedMotor.A0, SpeedMotor.AnalogRead) SpeedMotor.Initialize(0, SpeedMotor.AnalogRead) Read from the potentiometer.
Erel B4X founder Staff member Licensed User Longtime User Apr 16, 2017 #4 No. You will need to use a timer or looper. Upvote 0