PDA

View Full Version : memory button



docwisdom
- 12th February 2006, 07:45
I am hoping to create a memory button, much like that on a car radio. If you set a value, then hold the memory button for 2 seconds, it stores the value. From that point on, you can recall the memory by pressing the memory button. I guess what I'm asking is how do you make the 2 second time condition to do go to the write action versus the read.


thanks
-brian

Darrel Taylor
- 12th February 2006, 09:47
Hi Brian,

Me again.
Let me know if I'm giving too many answers ... :)

Try this on for size
WriteDelay CON 2000 ; ms
But VAR PORTB.0 ; The Button
LED1 VAR PORTB.1 ; Read indicator
LED2 VAR PORTB.2 ; Write indicator
DOWN CON 0 ; input state when button is DOWN
DelayCount VAR WORD ; Write delay Counter

Main:
GOSUB CheckButton
Goto Main

CheckButton:
IF But = Down then
DelayCount = 0
PAUSE 20 ; debounce
While But = Down
PAUSEUS 980
DelayCount = DelayCount + 1
IF DelayCount >= WriteDelay then ; Write detected
; ---- do the Write operation here ----
TOGGLE LED2
; -------------------------------------
While But = DOWN : Wend ; wait for button release
PAUSE 20 ; debounce
RETURN
ENDIF
WEND ; button was released before timeout
; ---- do the Read operation here ----
TOGGLE LED1
; ------------------------------------
PAUSE 20 ; debounce
ENDIF
RETURN