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.
sine-wave.cpp
00001 #include "mbed.h" 00002 #include "AnalogOut.h" 00003 #include "AnalogIn.h" 00004 #include <math.h> 00005 00006 #define I2C0_SDA PTE25 00007 #define I2C0_SCL PTE24 00008 #define MMA8451_I2C_ADDRESS (0x1d<<1) 00009 #define MAG3110_I2C_ADDRESS (0x0E<<1) 00010 #define LIGHT_SENSOR_PIN PTE22 00011 #define PI 3.141f 00012 00013 Serial pc_sine(USBTX, USBRX); 00014 Timer timer; 00015 00016 00017 void sine_wave() 00018 { 00019 int t = 0; 00020 float s; 00021 AnalogOut a(PTE30); 00022 while (1) { // sin(2 * PI * f * t / Fs) 00023 s = sin(2 * PI * 1 * t / 100.0); 00024 s = s/2 + .5; 00025 a.write(s); 00026 pc_sine.printf ("%f\n", s); 00027 if (t == 100) 00028 t = 0; 00029 else 00030 t++; 00031 wait(0.01); 00032 } 00033 } 00034 00035 void sine_wave_read() 00036 { 00037 AnalogIn a(PTB0); 00038 while(1) { 00039 pc_sine.printf("%f\n", a.read()); 00040 wait(0.01); 00041 } 00042 } 00043 00044 /* 00045 int main() { 00046 sine_wave(); 00047 00048 char c = pc_sine.getc(); 00049 00050 switch (c) { 00051 case '1':sine_wave(); 00052 break; 00053 case '2': sine_wave_read(); 00054 break; 00055 } 00056 } 00057 */
Generated on Tue Jul 12 2022 21:36:10 by
1.7.2