Help please, run a countdown timer whilst at the same time pole the keypad???

jay4708

New Member
Hello,

My son and I am writing a basic alarm program that includes a keypad and an LCD (serout on an O/P pin).

We have come to part of the code where we want to display a message on the LCD with a countdown time (5 seconds) and at the same time monitor the keypad for a key press.

I have written the code to pole the keypad for key presses and it has worked fine in other parts of the program I just cant get my head round how I can set up a timer to count down from 5 to 0 and display it on the screen but at the same time still pole the keypad!!!

Your help is much appreciated, and let me remind you 'novice here' so go easy on me and please explain as much as you can, thanks.

John
 

hippy

Ex-Staff (retired)
The trick is in having the keyboard polling routine return indicating key pressed or no key pressed, for example 0, 1, 2 etc for a key, $FF for none.

Then you can loop round updating the LCD at the same time as handling any keys, something like ...

Code:
Do
  Gosub ScanKeyPad
  If keyPress <> $FF Then
    Gosub HandleKey
  End If
  Gosub UpdateTimeAndLcd
Loop
 

hippy

Ex-Staff (retired)
You could have "Loop Until keyPress = 1" or similar but how best to handle loop exits would depend upon what code you had and what you wanted to achieve.
 
Top