I'm new to the whole microcontroller world, and have learned quite a lot in the last few days. I'm trying to take a momentary push button, and have it start a subroutine when pressed for a short period of time, and possibly another subroutine when it's pushed for a long period of time.
A quick and dirty snippet and explanation would be greatly appreciated.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I had to write a section of code to do just that the other day:
'''Measure button A hold time
'''@param MaxTime Maximum number of milliseconds to wait
Function TimeA (Optional In MaxTime As word = 65535) As word
TimeA = 0
Wait Until BUTTON_A = 1
Do Until BUTTON_A = 0
Wait 1 ms
If TimeA < MaxTime Then
TimeA = TimeA + 1
Else
Exit Sub
End If
Loop
End Function
In this code, BUTTON_A is a constant referring to an I/O pin. To run a different section of code, you'd need something like this:
Dim ButtonTime As Word
ButtonTime = TimeA
Select Case ButtonTime
'Pressed for less than 500 ms
Case < 500
SubA
'Pressed for 500 to 1000 ms
Case < 1000
SubB
End Select
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I'm new to the whole microcontroller world, and have learned quite a lot in the last few days. I'm trying to take a momentary push button, and have it start a subroutine when pressed for a short period of time, and possibly another subroutine when it's pushed for a long period of time.
A quick and dirty snippet and explanation would be greatly appreciated.
I had to write a section of code to do just that the other day:
In this code, BUTTON_A is a constant referring to an I/O pin. To run a different section of code, you'd need something like this: