Alright-so I need to break out each individual part of the program and write subroutines (I normally work in GM's obfuscated 68HC11 assembler...and I'm terrible at writing that too. I can read it pretty well though!) for each individual part, and then only call them when needed-this will speed up the loop, and should make it more responsive. In the GM assembler, stuff is placed in 1 of 5 timer loops, when the timer is up, do everything in that loop, next timer, next loop, etc. So some functions get called every 10ms, some every 40ms, some every 160ms, etc.
So, I've got five buttons that will get pressed total-four which will actually have to do something, and one that just toggles an output for it's duration. In my case here, I want to check all the front panel buttons at a rate fast enough that a buttonpress isn't missed. Right now, I have to press and hold the button for a "long click"...don't have to hold it down til it changes on the display but it's longer than just a quick push. Do I need to scan the five buttons every 10-100ms and return the results?
For example, Button1 is the "memory" function-pushing it 1 time should recall Memory A, pushing it again should increment to Memory B, pushing it a 3rd time should increment to Memory C, and the display should update to show which memory position we are in. To set a memory position, I want to set the frequency via the encoder (haven't written that yet) and do a long press-this should set the current memory position to the current frequency. If this is the case, I'll start a new thread on how I should define and setup the functions needed.
To do this, I think I need to define several functions, because the "memory" function of this, minus being able to set the memory, is almost the same as the "band select" function and the "mode select" function.
I think:
Define Buttonpress(whichbutton) function to handle debounce and long/short press, returning (Thisbutton, longpress) or (Thatbutton, shortpress) This function will get used for all buttons, but I might not care if it was a short press or a long press.
Define SetMemory(memoryx, currentVFO), return (memoryx) where memoryx is an integer decimal value up to 54 million. I'd like to store (memoryx) in flash or EEPROM, so that they are retained when the power is shut off.
Define Cycle(whichparameter) where if we call Cycle(memory) we advance one position in the memory, or if we call Cycle(band) we advance one position in the band, this would be simpler if I had 4 memory positions for each band and four bands, so that seems like I should make it that way. This might also work for Cycle(Something?) to select the magnitude of each step of the encoder, when the encoder button is pressed.
Then, lastly, I should define ScanButtons() to check the state of the buttons every so often, and act on the results if anything has changed.
I've shot and cooked an elephant, time to get out the fork and knife.