Help with code for Signal Generator using DDS ad9850 and LCD keypad16x2

Hello all. New to this forum and to Arduino. I have bought a Mega 2650 , AD9850 and a LCD keypad 16x2 and i want to control the frequency simply by the buttons and display the frequency on the LCD. I have downloaded a few testcodes and button grabber sketches and i got an ide how to do this in separate sketches but i cant do it in one sketch. If anyone can help out i would be very greatful. Im really enjoying the Arduino and i want to learn alot. Regards /Janne

Welcome, How well do you understand functions and the programming language of the Arduino. That is the essence of the solution to your problem of merging.

you must make a sort of choice/menu system on top level and from that calling one function that does what you want.

example you have now sketch1 with a loop and sketch2 with a loop and your new program should become (in pseudo code)

void loop()
  int choice = MenuChoice();  // KeyPress;
  case 1: loop1(); break;  // use better names that reflect the function e.g. sinus, triangel square etc
  case 2: loop2(); break;
  case 3: loop3(); break;
  case 4: loop4(); break;
  default: // do nothing

void loop1() ...


Im a beginner at programming the Arduino so this will really help. Thanks /Janne

Looking at the code on this page, what does each part of this code do?

What does tuningWord = frequency* 4294.967296f / 125.0f; do?
Is it possible to achieve the same result using hardware pins or theSPI library?

Thank you.

This is the full code that allows for interaction with AD9850

int PIN_RESET = 13;
int PIN_CLOCK = 11;
int PIN_DATA = 10;
void AD9850Reset() {
    digitalWrite(PIN_FREQ_UPDATE, 0);
    digitalWrite(PIN_RESET, 0);
    digitalWrite(PIN_RESET, 1);
    digitalWrite(PIN_RESET, 0);
    digitalWrite(PIN_CLOCK, HIGH);
    digitalWrite(PIN_CLOCK, LOW);
    digitalWrite(PIN_FREQ_UPDATE, 1);
    digitalWrite(PIN_FREQ_UPDATE, 0);
//frequency in Hertz
void AD9850Update(double frequency) {
    unsigned char i, w;
    long int tuningWord;
    tuningWord = frequency* 4294.967296f / 125.0f;
    shiftOut(PIN_DATA, PIN_CLOCK, LSBFIRST, tuningWord);
    shiftOut(PIN_DATA, PIN_CLOCK, LSBFIRST, tuningWord >> 8);
    shiftOut(PIN_DATA, PIN_CLOCK, LSBFIRST, tuningWord >> 16);
    shiftOut(PIN_DATA, PIN_CLOCK, LSBFIRST, tuningWord >> 24);
    shiftOut(PIN_DATA, PIN_CLOCK, LSBFIRST, 0x0);
    digitalWrite(PIN_FREQ_UPDATE, 1);
    digitalWrite(PIN_FREQ_UPDATE, 0);