Sub Process_Globals
'These global variables will be declared once when the application starts.
'Public variables can be accessed from all modules.
Public Serial1 As Serial
Private RunTime As ULong
Private BtnPin, LEDPin As Pin
Private LastState As Boolean = True
End Sub
Private Sub AppStart
Serial1.Initialize(115200)
Delay(1500)
Log("AppStart")
BtnPin.Initialize(0, BtnPin.MODE_INPUT_PULLUP) 'Pin D3 on the WeMos D1 Mini
BtnPin.AddListener("BtnState_StateChanged")
LEDPin.Initialize(2, LEDPin.MODE_OUTPUT) 'On board LED on the WeMos D1 Mini
LEDPin.DigitalWrite(True)
End Sub
Sub BtnState_StateChanged (State As Boolean)
Dim LongPress As Int = 1000, ShortPress As Int = 500
If Not(State) And LastState Then 'Button Pressed
LastState = State
RunTime = Millis() 'Runtime
End If
If State And Not(LastState) Then 'Button Released
If ((Millis() - RunTime) <= ShortPress) And ((Millis() - RunTime) <= LongPress) Then
LEDPin.DigitalWrite(Not(LEDPin.DigitalRead)) 'Toggle LED On/Off for test purposes
Log("Short press") 'Run some code
End If
If (Millis() - RunTime) > LongPress Then
Log("Long press") 'Run some code
End If
End If
LastState = State
End Sub