/*//========================
AD9833 Signal Generator
Pinout Purple :
1 2 3 4 5 6 7
Ref-Vcc-Gnd-Dat-Clk-Fnc-Out
By Arf S
Board : Arduino Uno
Analog : 10-bits (0-1023)
switch Mode : 2
switch On : 3
========================*/
//#include<AD9833.h>
#include <LiquidCrystal_I2C.h> // if you don´t have I2C version of the display, use LiquidCrystal.h library instead
#define Ain A3
#define swMod 2
#define swOn 3
//AD9833 gen(9);
long f;
int sw1, sw2, mode;
bool onof;
LiquidCrystal_I2C lcd(0x27,16,2); // set the LCD address to 0x27 for a 16 chars and 2 line display
//====================SETUP====================
void setup()
{
lcd.init(); // initialize the 16x2 lcd module
lcd.backlight(); // enable backlight for the LCD module
pinMode(swMod,INPUT_PULLUP); pinMode(swOn,INPUT_PULLUP);
// gen.Begin();
// gen.EnableOutput(true);
lcd.setCursor(0,0); lcd.print("AD9833 GENERATOR");
lcd.setCursor(0,1); lcd.print("--------------- ");
delay(1000);
}
//===================LOOP=====================
void loop()
{
f = map(analogRead(Ain),0,1023,1,5000);
ceksw();
// lcd.setCursor(0,0); lcd.print("Freq: 0000000 Hz");
lcd.setCursor(0,0); lcd.print("Freq: "); lcd.print(f); lcd.print(" Hz ");
lcd.setCursor(0,1);
if (mode==0) {lcd.print("Mode: Sin ");}
if (mode==1) {lcd.print("Mode: Tri ");}
if (mode==2) {lcd.print("Mode: Sqr ");}
if (onof==0) {lcd.print("- OFF");}
if (onof==1) {lcd.print("- ON ");}
//if(sw1==LOW && sw2==LOW) gen.ApplySignal(SINE_WAVE,REG0,f);
//if(sw1==LOW && sw2==HIGH) gen.ApplySignal(TRIANGLE_WAVE,REG0,f);
//if(sw1==HIGH && sw2==LOW) gen.ApplySignal(SQUARE_WAVE,REG0,f);
//if(sw1==HIGH && sw2==HIGH) gen.ApplySignal(HALF_SQUARE_WAVE,REG0,f);
delay(50);
}
void ceksw(){
sw1 = digitalRead(swMod);
sw2 = digitalRead(swOn);
if (!sw1) {onof=!onof;delay(100);}
if (!sw2) {mode++; if(mode>=3){mode=0;} delay(100);}
}