B4R Question Node MCU Listener Problem - SOLVED

JMB

Active Member
Licensed User
Longtime User
I have a NodeMCU with a switch to ground on one of the pins.

I've defined the pin as an input with a pullup resistor, and I've added a listener to the pin.

When I press the switch, the listener code runs once - and that's it. It comes back with the correct pin. But it only responds once.

The code is shown below.

B4X:
btn.Initialize(16, btn.MODE_INPUT_PULLUP) 'Using the internal pull up resistor to prevent the pin from floating.
btn.AddListener("Btn_StateChanged")

The Listener code...

B4X:
Sub Btn_StateChanged (State As Boolean)
   Log("state: ", State)
   Log("this code called")
   Dim p As Pin = Sender
   Log("Pin: ", p.PinNumber, ", state: ", State)
End Sub

Can anyone shed some light on this?

Thanks!

JMB
 

JMB

Active Member
Licensed User
Longtime User
Sorted. I changed pin. Should have thought of that myself!

Thanks for your help.

JMB
 
Upvote 0
Top