Sub Process_Globals
Public Serial1 As Serial
Private tm As TM1637Display
Private counter As Int
Private buttonPin As Pin
Private lastButtonState As Boolean
Private lastDebounceTime As Long
Private debounceDelay As Long
End Sub
Private Sub AppStart
Serial1.Initialize(115200)
Log("AppStart")
tm.Initialize(2, 3) ' Initialize the display
buttonPin.Initialize(4, 0) ' Initialize button pin (change 4 to your actual button pin)
counter = 0 ' Initialize counter to 0
lastButtonState = False
lastDebounceTime = 0
debounceDelay = 50 ' Adjust debounce delay as needed
' Set up a loop to continuously check the button state
Dim loopTimer As Timer
loopTimer.Initialize("LoopTimer_Tick", 50)
loopTimer.Enabled = True
End Sub
Sub LoopTimer_Tick
Dim currentButtonState As Boolean
currentButtonState = buttonPin.Read() = 0 ' Assuming button press pulls the pin low (change to 1 if high)
' Check if the button state has changed and debounce
If currentButtonState <> lastButtonState Then
lastDebounceTime = Millis
End If
If (Millis - lastDebounceTime) > debounceDelay Then
If currentButtonState <> lastButtonState Then
lastButtonState = currentButtonState
' Increment counter if button is pressed
If currentButtonState = True Then ' Button pressed
counter = counter + 1
tm.ShowNumberDec2(counter, True, 4, 0)
End If
End If
End If
End Sub