This is lab2 of 4180 dealing with the extra parts kit.

Dependencies:   mbed LSM9DS1_Library_cal

Committer:
jbaker66
Date:
Fri Feb 12 17:37:34 2016 +0000
Revision:
3:8e9172f7d119
Parent:
2:4401fc907d45
Child:
4:1443e98048a6
AnalogOut working;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Jesse Baker 2:4401fc907d45 1 // <- remove this if you want to code this and comment Georges
Jesse Baker 2:4401fc907d45 2 #include "mbed.h"
Jesse Baker 2:4401fc907d45 3
Jesse Baker 2:4401fc907d45 4 AnalogOut aout(p18);
Jesse Baker 2:4401fc907d45 5
jbaker66 3:8e9172f7d119 6 int main(){
Jesse Baker 2:4401fc907d45 7 const double pi = 3.141592653589793238462;
jbaker66 3:8e9172f7d119 8 const double amplitude = 1;
Jesse Baker 2:4401fc907d45 9 const double offset = 65535/2;
Jesse Baker 2:4401fc907d45 10 double rads = 0.0;
Jesse Baker 2:4401fc907d45 11 uint16_t sample = 0;
jbaker66 3:8e9172f7d119 12
jbaker66 3:8e9172f7d119 13 while(1){
Jesse Baker 2:4401fc907d45 14 // sinewave output
Jesse Baker 2:4401fc907d45 15 for (int i = 0; i < 360; i++) {
Jesse Baker 2:4401fc907d45 16 rads = (pi * i) / 180.0f;
Jesse Baker 2:4401fc907d45 17 sample = (uint16_t)(amplitude * (offset * (cos(rads + pi))) + offset);
Jesse Baker 2:4401fc907d45 18 aout.write_u16(sample);
Jesse Baker 2:4401fc907d45 19 }
Jesse Baker 2:4401fc907d45 20 }
Jesse Baker 2:4401fc907d45 21 }
jbaker66 3:8e9172f7d119 22