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.
Dependencies: mbed
main.cpp
00001 #include "mbed.h" 00002 00003 AnalogOut Aout(p18); 00004 AnalogIn Ain(p20); 00005 //AnalogIn Ain1(p19); 00006 //AnalogIn Ain2(p20); 00007 00008 DigitalIn sw1(p7); 00009 DigitalIn sw2(p8); 00010 DigitalIn sw3(p9); 00011 DigitalIn sw4(p10); 00012 00013 int main() { 00014 float A,T,f,Ts;//A=amplitude, T=period, f=frequency, Ts= sampling time 00015 const float PI=3.141592; 00016 int SinNumPoints=100; 00017 00018 //with only one potenciometer 00019 while(1) { 00020 if (sw1==1){//mode1: amplitude control 00021 A=Ain; 00022 f=50000; 00023 T=1/f; 00024 Ts= T/SinNumPoints; 00025 for (int i=0;i<SinNumPoints;i++){ 00026 Aout=0.5+A/2*sin(2*PI*f*i*Ts); 00027 wait(Ts); 00028 }else if(sw2==1){// mode2: period control 00029 A=1; 00030 f=50000*Ain; 00031 T=1/f; 00032 Ts= T/SinNumPoints; 00033 for (int i=0;i<SinNumPoints;i++){ 00034 Aout=0.5+A/2*sin(2*PI*f*i*Ts); 00035 wait(Ts); 00036 } 00037 /* with 2 potenciometer to control simuntaneously both parameter, amplitude and frequency 00038 00039 while(1){ 00040 A=Ain1; 00041 f=50000*Ain2;(20ms) 00042 T=1/f; 00043 Ts=T/SinNumPoints; 00044 for (int i=0;i<SinNumPoints;i++){ 00045 Aout=0.5+A/2*sin(2*PI*f*i*Ts); 00046 wait(Ts); 00047 } 00048 } 00049 00050 */ 00051 } 00052 00053 } 00054 }
Generated on Thu Jul 28 2022 05:23:44 by
1.7.2