|Hardware Switch Scanning
|Page 1 of 1|
|Author:||Straylight [ Mon Jul 08, 2019 7:10 pm ]|
|Post subject:||Hardware Switch Scanning|
I've been working on a 68k based hardware project for a while as a hobby. I have been trying to implement a button function but I'm having trouble figuring out a way to do it.
The problem I'm currently having with my code is that if the button is held down, the option I want is repeatedly changed every time the program loops around again so I kinda hacked it with multiple btst. Also, with my current code the option changes the first time the button is pushed.
What I want is to press the button, the LCD displays an option (eg "Hello World!"), click the button again, the option changes (eg "Goodbye World"), save that state when the screen is exited. If the state was "Goodbye" and I press the button from some other menu, I want it to say "Goodbye" and not change on the button push entry. Any advice? Here is my current rough code:
dc.b ' Hello '
dc.b ' World! '
dc.b ' Goodbye '
dc.b ' World! '
|Author:||marc_256 [ Fri Jul 12, 2019 2:13 pm ]|
|Post subject:||Re: Hardware Switch Scanning|
I think the best way to do this is to use two variables.
CLEAR THE VARIABLES BY START OF THE PROGRAM
Read button input
If your button is released the ButtonStatus = 0
If you push the button the ButtonStatus = 1
If ButtonStatus = 1 and ButtonStateOld = 0 then
ButtonStateNew = 1
ElseIf ButtonStatus = 1 and ButtonStateOld = 1 then
ButtonStateNew = 2
Do your stuff ...
ButtonStateOld = ButtonStateNew
ButtonStateNew = 0
|Page 1 of 1||All times are UTC|
|Powered by phpBB® Forum Software © phpBB Group