Alright. I think I may have made some progress here, this is a new "subroutine" I worked out to replace some of the button code for button2 (the memory button)
pinMode(button2, INPUT_PULLUP);
int currentMemory = 0;
volatile uint32_t currentFrequency;
void Memorybutton(){
int held = 0;
delay(200); //debounce the button
while ((button2 == LOW) && held <=10) {
delay(100);
held++;
}
if (held <10){
Setmemory(currentMemory, currentFrequency);
}
else {
(currentMemory++);
}
}
void Setmemory(int currentMemory, volatile uint32_t currentFrequency){
}
Keep in mind, Setmemory hasn't been defined yet, because I'm not sure how. MemoryButton() seems to be OK, I think it does what I need.
First, defining currentMemory, and currentFrequency. Both of these are "global" because other functions will use them too. Current frequency changes by the encoder so I think it should be a volatile?
I made MemoryButton() type void, because it doesn't return anything, I just call it when I check the buttons.
held is locally defined variable, it's only used inside the function. The delay(200) is supposed to be a debounce-but I think it may be in the wrong spot?
The while loop is supposed to differentiate between a short press and a long press. If the button is held down longer than delay(100), increment the held counter, and if the button is held down for longer than 10 increments of held, it's a long button push-call Setmemory. If less than 10 increments of held, increment the currentMemory variable by 1.
The desired behavior is that a short press will increment from Memory Position 1, to Memory Position 2, and so on. A long press will NOT increment Memory Position, but will instead save the currentFrequency value to non-volatile memory.
Setmemory will have to wait a bit until I get the other button functions worked out. It will involve an EEPROM write, so it's a bit more advanced than I am yet. Also, I need to learn how to configure the parameters so that when you call Setmemory(arg1, arg2) that it knows that arg1 is the current memory position, and arg2 is the current frequency setting.