Devices & Components
Arduino Uno Rev3
Software & Tools
Arduino IDE
Project description
Code
ARDUINO UNO - WAVEFORM GENERATOR AND FILTER
c_cpp
Load this sketch to Arduino Uno
1/************************************************************************************** 2 ARDUINO UNO - WAVEFORM GENERATOR AND FILTER - JULIO CESAR - JCR - 09/21 3 **************************************************************************************/ 4/* Instructions: connect Arduino Uno to PC or Notebook via USB cable, choose one of the functions to be plotted 5 (SAW, SQR, FILTER and SINE), load the sketch in Arduino Uno, go to the Tools menu and open the Serial Plotter. */ 6 7byte filter; 8byte saw; 9byte sqr; 10int sine; 11int angle; 12 13void setup() { 14 Serial.begin(19200); 15} 16 17void loop() { 18 delay(5); 19 saw_square_gen(); 20 filter_lowpass(); 21 sine_gen(); 22 23 //Comment out one the below Serial.println() waveform you want to plot (one at a time): 24 //Serial.println(saw); 25 //Serial.println(sqr); 26 //Serial.println(filter); 27 Serial.println(sine); 28} 29 30void saw_square_gen() { //SAW & SQUARE WAVE GEN 31 saw = saw + 1; 32 if (saw > 127 && saw < 256) sqr = 255; else sqr = 1; 33} 34 35void sine_gen() { //SINE WAVE GEN 36 angle = angle + 1; if (angle > 360) angle = 0; 37 //sine = 50 * sin((angle * PI / 180)); 38 sine = 50 * sin(angle * 0.0174532925); 39 //sine = abs(sine); 40} 41 42void filter_lowpass() { //DIGITAL FILTER 43 filter = filter * 0.9 + sqr * 0.1; 44}
Downloadable files
Schematics
Needed to work.
Schematics

Schematics
Needed to work.
Schematics

Comments
Only logged in users can leave comments