Sub Process_Globals
Public Serial1 As Serial
Private btn As Pin
Private timer1 As Timer
Private i As UInt=0
End Sub
Private Sub AppStart
Serial1.Initialize(115200)
Log("AppStart")
btn.Initialize(btn.A0, btn.MODE_INPUT_PULLUP) 'Using the internal pull up resistor to prevent the pin from floating.
btn.AddListener("Btn_StateChanged")
timer1.Initialize("timer1_Tick",1000)
Log("Waiting....")
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.
If State=False Then
timer1.Enabled=True
Log("Button pressed")
Else
timer1.Enabled=False
Log("Button released")
i=0
End If
End Sub
Sub timer1_Tick
'turn on motor till button is release or whatever
i=i+1
Log("i= ",i)
End Sub