I need to add a push button to my project and decided that using the analog pin was the way to go so I don't tie up another digital pin in case I need one for something else.
I followed the example here but I can't get an event to fire.
I have a timer that displays temperature readings every 5 seconds and I added a line to show the input value of A0:
Why doesn't the button press event fire? When connected as shown in the example, why does it read 8 either way? I'm certain that Erel's tutorial works on that particular board, so do I need to do something different with the ESP-12E?
I am considering adding a Looper to monitor the value of A0 but isn't that the point of adding a listener? Could doing that affect performance of the program overall?
I followed the example here but I can't get an event to fire.
I have a timer that displays temperature readings every 5 seconds and I added a line to show the input value of A0:
- When wired exactly as shown in the example (Grnd to switch, switch to A0), no event fires, and A0 reads around 8 whether the button is pressed or not.
- When wired 3v3 to switch, switch to A0, no event fires but A0 does read 1024 when the button is pressed (8 when not pressed).
Why doesn't the button press event fire? When connected as shown in the example, why does it read 8 either way? I'm certain that Erel's tutorial works on that particular board, so do I need to do something different with the ESP-12E?
I am considering adding a Looper to monitor the value of A0 but isn't that the point of adding a listener? Could doing that affect performance of the program overall?
B4X:
' Only showing the relevant parts here...
Private Sub AppStart
btnHeatToggle.Initialize(btnHeatToggle.A0, btnHeatToggle.MODE_INPUT_PULLUP) 'Using the internal pull up resistor to prevent the pin from floating.
btnHeatToggle.AddListener("btnHeatToggle_StateChanged")
End Sub
Sub btnHeatToggle_StateChanged (State As Boolean) ' <------- This event never fires
Delay(20) 'wait for 20 milliseconds - should help to minimize switch bounce
Log("Button state: ", State)
If State = False Then 'False means button pressed.
HeatPumpRun = Not(HeatPumpRun)
hpRelay.DigitalWrite(HeatPumpRun)
UpdateDisplay
If Logging Then
Dim sText As String
sText = JoinStrings(Array As String("HeatPumpRun = ", HeatPumpRun))
WriteLog(sText, True)
End If
End If
End Sub