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

Dependencies:   mbed LSM9DS1_Library_cal

Committer:
Jesse Baker
Date:
Fri Feb 12 11:40:01 2016 -0500
Revision:
2:4401fc907d45
Parent:
0:58f21c3e8813
Child:
3:8e9172f7d119
testing AnalogOut JB

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 #include "DebounceIn.h"
Jesse Baker 2:4401fc907d45 4 #include "PinDetect.h"
Jesse Baker 2:4401fc907d45 5
Jesse Baker 2:4401fc907d45 6 AnalogOut aout(p18);
Jesse Baker 2:4401fc907d45 7
Jesse Baker 2:4401fc907d45 8 int main()
Jesse Baker 2:4401fc907d45 9 {
Jesse Baker 2:4401fc907d45 10 const double pi = 3.141592653589793238462;
Jesse Baker 2:4401fc907d45 11 const double amplitude = 0.5f;
Jesse Baker 2:4401fc907d45 12 const double offset = 65535/2;
Jesse Baker 2:4401fc907d45 13 double rads = 0.0;
Jesse Baker 2:4401fc907d45 14 uint16_t sample = 0;
Jesse Baker 2:4401fc907d45 15
Jesse Baker 2:4401fc907d45 16 while(1) {
Jesse Baker 2:4401fc907d45 17 // sinewave output
Jesse Baker 2:4401fc907d45 18 for (int i = 0; i < 360; i++) {
Jesse Baker 2:4401fc907d45 19 rads = (pi * i) / 180.0f;
Jesse Baker 2:4401fc907d45 20 sample = (uint16_t)(amplitude * (offset * (cos(rads + pi))) + offset);
Jesse Baker 2:4401fc907d45 21 aout.write_u16(sample);
Jesse Baker 2:4401fc907d45 22 }
Jesse Baker 2:4401fc907d45 23 }
Jesse Baker 2:4401fc907d45 24 }