I am looking for a way to measure the amount of time a button has been pressed.
1st press of the button turns on the system (working)
2nd press turns additional features (working)
3rd press turns everything off, but what I need is some type of delay that prevent accidentally turning off the system. So when I press the button a 3rd time and hold it for 3 seconds then the system will shut itself off.
What is the best way to do this.
Code: Select all
'Check to see if the start button has been pressed
'
'
Sub PowerButtonTask()
Do
' Wait for a button press
Call WaitForInterrupt(zxPinFallingEdge, 0)
'
' Toggle the device state
'
Call PutPin(RelayPin, IIf(deviceIsOn, Power_off, Power_On))
Call PutPin(RedLED, LEDon)
Call Putpin(PowerLED, LEDon)
deviceIsOn = not deviceIsOn
'Call Delay(0.500) '500mS time delay
'
'If the power is on then go check if button has been pressed a second time
'Turn on the wireless receiver
If deviceIsOn = True and LowBatt = False then
Call WaitForInterrupt(zxPinrisingEdge, 0)
Call PutPin(GreenLED, LEDon)
Call PutPin(Wirelesspin, Power_On)
Call LCD_DisplayStrAt("W", 1, 15)
end if
'
'If the button has been pressed a 3rd time turn everything off
'
If deviceIsOn = False then
Call PutPin(GreenLED, LEDoff)
Call PutPin(RedLED, LEDoff)
Call PutPin(PowerLED, LEDoff)
Call Putpin(Wirelesspin, Power_off)
Call LCD_Clear()
end if
'
' Time delay for switch debounce
'
Call Delay(0.500) '500mS time delay
Loop
End Sub
Thanks for the help
Patrick