const int tombol1 = 2; // Pushbutton 1 const int tombol2 = 3; // Pushbutton 2 const int tombol3 = 4; // Pushbutton 3 int status1 = 0; int status2 = 0; int status3 = 0; long f = 0; #define W_CLK 8 // Pin 8 - connect to AD9850 module word load clock pin (CLK) #define FQ_UD 9 // Pin 9 - connect to freq update pin (FQ) #define DATA 10 // Pin 10 - connect to serial data load pin (DATA) #define RESET 11 // Pin 11 - connect to reset pin (RST). #define pulseHigh(pin) {digitalWrite(pin, HIGH); digitalWrite(pin, LOW); } // transfers a byte, a bit at a time, LSB first to the 9850 via serial DATA line void tfr_byte(byte data) { for (int i=0; i<8; i++, data>>=1) { digitalWrite(DATA, data & 0x01); pulseHigh(W_CLK); //after each bit sent, CLK is pulsed high } } // frequency calc from datasheet page 8 = * /2^32 void sendFrequency(double frequency) { int32_t freq = frequency * 4294967295/125000000; // note 125 MHz clock on 9850 for (int b=0; b<4; b++, freq>>=8) { tfr_byte(freq & 0xFF); } tfr_byte(0x000); // Final control byte, all 0 for 9850 chip pulseHigh(FQ_UD); // Done! Should see output } void setup() { // configure arduino data pins for output pinMode(FQ_UD, OUTPUT); pinMode(W_CLK, OUTPUT); pinMode(DATA, OUTPUT); pinMode(RESET, OUTPUT); pulseHigh(RESET); pulseHigh(W_CLK); pulseHigh(FQ_UD); // this pulse enables serial mode - Datasheet page 12 figure 10 pinMode(tombol1, INPUT); pinMode(tombol2, INPUT); pinMode(tombol3, INPUT); Serial.begin(9600); sendFrequency(400); // freq delay (5000); sendFrequency(1300); // freq delay (5000); sendFrequency(3000); // freq delay (5000); } void loop() { status1 = digitalRead(tombol1); status2 = digitalRead(tombol2); status3 = digitalRead(tombol3); if (status1 == HIGH) { outermarker(); Serial.println ("Outer Marker"); } else { notone(); } if (status2 == HIGH) { midlemarker(); Serial.println ("Midle Marker"); } else { notone(); } if (status3 == HIGH) { innermarker(); Serial.println ("Inner Marker"); } else { notone(); } } void notone(){ sendFrequency(0); // freq } void outermarker(){ sendFrequency(400); // freq delay(500); sendFrequency(0); // freq delay(100); sendFrequency(400); // freq } void midlemarker(){ sendFrequency(1300); // freq delay(200); sendFrequency(0); // freq delay(100); sendFrequency(1300); // freq delay(500); } void innermarker(){ sendFrequency(3000); // freq delay(150); sendFrequency(0); // freq delay(150); }