Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
00001 #include "mbed.h" 00002 00003 #define PI 3.142 00004 #define AMP 0.8 00005 00006 #define SIGNAL_OUTPUT_FREQ 25//usec 00007 // coz twice zone of human audibility 00008 AnalogOut signal(p18); 00009 AnalogIn adin(p17); 00010 00011 Ticker t_wave; 00012 00013 float freq; 00014 00015 float wave_value; 00016 void sawtoothWave(){ 00017 wave_value+=freq*SIGNAL_OUTPUT_FREQ/1000000; 00018 if(wave_value > 1.0) 00019 wave_value = 0.0; 00020 float output = AMP*wave_value; 00021 signal = output; 00022 } 00023 00024 float theata; 00025 void sinWave(){ 00026 theata += 2*PI*SIGNAL_OUTPUT_FREQ*freq/1000000; 00027 if(theata > 2*PI) 00028 theata = 0.0; 00029 float output = AMP*( sin(theata)+0.5 ); 00030 signal = output; 00031 } 00032 00033 int main() { 00034 wave_value = 0.0; 00035 freq = 1000; 00036 t_wave.attach_us(&sinWave , SIGNAL_OUTPUT_FREQ); 00037 while(1){ 00038 freq = 5000*adin.read(); 00039 } 00040 }
Generated on Wed Jul 27 2022 01:41:14 by
1.7.2