Hi,
I guess i have one more question about the while loop for a program fromMelanie:
Here is a snip if the code
While MyButton=0 'PORTB.0, zero when not pressed, 1 when pressed
If ButtonPress<255 then ButtonPress=ButtonPress+1
Pause 50 ' This is also our Debounce value
Wend
The problem with this is that I have a battery charger Subroutine in there. Therefore the code looks like this.
While MyButton=0 'PORTB.0, zero when not pressed, 1 when pressed
If ButtonPress<255 then ButtonPress=ButtonPress+1
Pause 50 ' This is also our Debounce value
Gosub Charge_Battery ' takes hours to charge
Wend
Therefore MyButton is going to increment very rarely. Almost never. In Melanie's code there is also the option of Longpress, which requires to hold the button for a few seconds. This is what I need, How do I incorporate this Longpress into my program.??
Here is Melanie's full code:
MyButton var PortB.0 ' Your Button can be anywhere
' Connect between PIC pin and Vss
' Use Weak Pull-Up or Resistor to Vdd
ButtonPress var BYTE ' Button Counter Variable
LongPress con 20 ' Change this value for desired SET
' function trip-point in 50mS steps
' Currently set for 1 Second
MainLoop:
LCDOut $FE,1,"Go Press..."
ButtonLoop:
Gosub GetButton
If ButtonPress>0 then
If ButtonPress=1
LCDOut $FE,1,"Short Press"
else
LCDOut $FE,1,"Long Press"
endif
Pause 1000
Goto MainLoop
endif
Goto ButtonLoop
'
' Subroutine weighs-up users finger
' in multiples of 50mS
' Constant LONGPRESS determines boredom level
' -------------------------------------------
' on Exit...
' ButtonPress=0 - No Press
' ButtonPress=1 - Short Press
' ButtonPress=2 - Long Press
GetButton:
ButtonPress=0
While MyButton=0 'PORTB.0, zero when not pressed, 1 when pressed
If ButtonPress<255 then ButtonPress=ButtonPress+1
Pause 50 ' This is also our Debounce value
Wend
If ButtonPress>0 then
If ButtonPress=>LongPress then
ButtonPress=2
else
ButtonPress=1
endif
endif
Return




Bookmarks