Arduino VFO, function and sweep generator - keypad control

Hello there! I've been working with this project for some weeks. I want to pair an arduino mega with a 128x64 graphic lcd, an AD9850 module and a keypad to control the whole thing.

My only problem is with the keypad control. It is done in a strange way. The problem is that i would like to treat button presses like interrupts, which take actions if the buttons are pressed.

So far i can enter the frequency on the keypad, and then press # to send it to the AD9850 module. The problem is that the whole program is built around the IF statement. IF a button is pressed, it does what is in the code. It is working okay, but is getting harder and harder to implement new functions. I attached the relevant source code for better understanding. The principle: When a key is pressed, it decides if it is a *, then is zeroes the output value; if it is a number, it adds to the string, as long as you press the #, then it sends it to the dds module, and zeroes the string.

I want to make a simple user interface with frequency input options, maybe a calibration menu.

For example, if i push the * key, go into frequency enter mode, and when pressing * again, it applies and sends the desired frequency. When pushing the # go into the menu, and so on. With the current architecture, I can't detect presses one after one, as the whole block is built around a single key press.

My main question is that how can i make this program to only care about the keypad if a button is pressed? Not constantly listening, and if pressed, then comes the whole program.

void loop(){

char key = keypad.getKey();

if (key){

value+=key; if(key=='*') {value="";} GLCD.println(value); if(key=='#') {dds.setFrequency(value.toInt());value="";} GLCD.CursorTo(0,0);



Thanks for your help in advance. IMHO it is not a directly arduino related program, more of a control logic problem, but i hope you can help me with this interesting idea.

The problem is that i would like to treat button presses like interrupts

That sounds like a self-inflicted problem.

. I attached the relevant source code

No you didn't