B4X:
Sub Process_Globals
Public Serial1 As Serial
Private btn As Pin
Private led As Pin
End Sub
Private Sub AppStart
Serial1.Initialize(115200)
Log("AppStart")
led.Initialize(13, led.MODE_OUTPUT)
btn.Initialize(btn.A0, btn.MODE_INPUT_PULLUP) 'Using the internal pull up resistor to prevent the pin from floating.
btn.AddListener("Btn_StateChanged")
End Sub
Sub Btn_StateChanged (State As Boolean)
Log("state: ", State)
'state will be False when the button is clicked because of the PULLUP mode.
led.DigitalWrite(Not(State))
End Sub