Hi, I am using a Nano and a AD9833. I am trying to set the frequency output of the 9833 according to what digital input pin is high. I can set successfully the inital frequency by changing the "long Freq" declaration, but none of the if statements ever evaluate to High. I have verified that I have 5v going to the pin, and also a pull down resistor. I can't get the if statement to evaluate true no matter what I do.
Here is my code:
#include <Wire.h> //for I2C
#include <MD_AD9833.h> //for Frequency Generator
// Pins for SPI comm with the AD9833 IC
#define DATA 11 ///< SPI Data pin number
#define CLK 13 ///< SPI Clock pin number
#define FSYNC 10 ///< SPI Load pin number
MD_AD9833 AD(FSYNC); // Hardware SPI
// the regular (waveform select) button:
int freq1=2; // for selecting 1000 Hz
int freq2=3; // for selecting 2000 Hz
long Freq = 1000; // starting frequency
void setup() {
Serial.begin(9600); // open the serial port at 9600 bps:
pinMode(freq1, INPUT); // sets the digital pin as input
pinMode(freq2, INPUT); // sets the digital pin as input
//go ahead and set the frequency to whatever is currently selected
if (freq1 == HIGH) {
//set freq to 1000HZ
Freq = 1000;
}else if (freq2 == HIGH) { //add next frequency here
//set freq to 2000HZ
Freq = 2000;
}
AD.begin(); // start the generator board
delay(1000);
AD.setMode(MD_AD9833::MODE_SINE);
AD.setFrequency(MD_AD9833::CHAN_0, Freq);
}
void loop() {
if (freq1 == HIGH) { // read the input pin
//set freq to 1000HZ
Freq = 1000;
} else if (freq2 == HIGH) { //add next frequency here
//set freq to 2000HZ
Freq = 2000;
}
AD.setFrequency(MD_AD9833::CHAN_0, Freq);
delay(500);
}