Hello all
This is the same as Erel's "Button Example" modified by Klaus. All what I did is replacing the mechanical switch with a touch switch module. So simple that the images speak for themselves.
BTW: for your convenience I am putting the code here.
This is the same as Erel's "Button Example" modified by Klaus. All what I did is replacing the mechanical switch with a touch switch module. So simple that the images speak for themselves.
BTW: for your convenience I am putting the code here.
B4X:
Sub Process_Globals
Public Serial1 As Serial
Private pinButton As Pin 'pin for the button
Private pinLED13 As Pin 'pin for the green Led
Private LightOn = False As Boolean
End Sub
Private Sub AppStart
Serial1.Initialize(115200)
pinButton.Initialize(pinButton.A0, pinButton.MODE_INPUT_PULLUP) 'Using the internal pull up resistor to prevent the pin from floating.
pinButton.AddListener("pinButton_StateChanged")
pinLED13.Initialize(13, pinLED13.MODE_OUTPUT)
pinLED13.DigitalWrite(LightOn) 'sets LED13 according to LightOn
End Sub
Private Sub pinButton_StateChanged (State As Boolean)
If State = False Then 'remember, False means button pressed.
LightOn = Not(LightOn)
pinLED13.DigitalWrite(LightOn)
End If
End Sub
Last edited: