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

Dependencies:   mbed LSM9DS1_Library_cal

Committer:
Jesse Baker
Date:
Fri Feb 12 12:59:08 2016 -0500
Revision:
5:d3dfaed9fd93
Parent:
4:1443e98048a6
Child:
6:713054b45e91
testing IR sensor

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
jbaker66 4:1443e98048a6 4 // --------------------------------------------------------------------------------
Jesse Baker 2:4401fc907d45 5
jbaker66 4:1443e98048a6 6 //// AnalogOut sine wave complete
jbaker66 4:1443e98048a6 7 //AnalogOut aout(p18);
jbaker66 4:1443e98048a6 8 //
jbaker66 4:1443e98048a6 9 //int main(){
jbaker66 4:1443e98048a6 10 // const double pi = 3.141592653589793238462;
jbaker66 4:1443e98048a6 11 // const double amplitude = 1;
jbaker66 4:1443e98048a6 12 // const double offset = 65535/2;
jbaker66 4:1443e98048a6 13 // double rads = 0.0;
jbaker66 4:1443e98048a6 14 // uint16_t sample = 0;
Jesse Baker 5:d3dfaed9fd93 15 //
jbaker66 4:1443e98048a6 16 // while(1){
jbaker66 4:1443e98048a6 17 // // sinewave output
jbaker66 4:1443e98048a6 18 // for (int i = 0; i < 360; i++) {
jbaker66 4:1443e98048a6 19 // rads = (pi * i) / 180.0f;
jbaker66 4:1443e98048a6 20 // sample = (uint16_t)(amplitude * (offset * (cos(rads + pi))) + offset);
jbaker66 4:1443e98048a6 21 // aout.write_u16(sample);
jbaker66 4:1443e98048a6 22 // }
jbaker66 4:1443e98048a6 23 // }
jbaker66 4:1443e98048a6 24 //}
jbaker66 4:1443e98048a6 25 // --------------------------------------------------------------------------------
jbaker66 3:8e9172f7d119 26
jbaker66 4:1443e98048a6 27 // Sharp IR sensor
jbaker66 4:1443e98048a6 28
Jesse Baker 5:d3dfaed9fd93 29 Serial pc(USBTX, USBRX);
jbaker66 4:1443e98048a6 30
Jesse Baker 5:d3dfaed9fd93 31 AnalogIn sensor(p15);
Jesse Baker 5:d3dfaed9fd93 32 DigitalOut led1(LED1);
Jesse Baker 5:d3dfaed9fd93 33 DigitalOut led2(LED2);
Jesse Baker 5:d3dfaed9fd93 34 DigitalOut led3(LED3);
Jesse Baker 5:d3dfaed9fd93 35 DigitalOut led4(LED4);
Jesse Baker 5:d3dfaed9fd93 36
Jesse Baker 5:d3dfaed9fd93 37 int main(){
Jesse Baker 5:d3dfaed9fd93 38 while(1){
Jesse Baker 5:d3dfaed9fd93 39
Jesse Baker 5:d3dfaed9fd93 40 // if(sensor > 0.4){
Jesse Baker 5:d3dfaed9fd93 41 // led1 = 1;
Jesse Baker 5:d3dfaed9fd93 42 // led2 = 0;
Jesse Baker 5:d3dfaed9fd93 43 // led3 = 0;
Jesse Baker 5:d3dfaed9fd93 44 // led4 = 0;
Jesse Baker 5:d3dfaed9fd93 45 // }
Jesse Baker 5:d3dfaed9fd93 46 // else if(sensor > 1.3){
Jesse Baker 5:d3dfaed9fd93 47 // led1 = 1;
Jesse Baker 5:d3dfaed9fd93 48 // led2 = 1;
Jesse Baker 5:d3dfaed9fd93 49 // led3 = 0;
Jesse Baker 5:d3dfaed9fd93 50 // led4 = 0;
Jesse Baker 5:d3dfaed9fd93 51 // }
Jesse Baker 5:d3dfaed9fd93 52 // else if(sensor > 2.2){
Jesse Baker 5:d3dfaed9fd93 53 // led1 = 1;
Jesse Baker 5:d3dfaed9fd93 54 // led2 = 1;
Jesse Baker 5:d3dfaed9fd93 55 // led3 = 1;
Jesse Baker 5:d3dfaed9fd93 56 // led4 = 0;
Jesse Baker 5:d3dfaed9fd93 57 // }
Jesse Baker 5:d3dfaed9fd93 58 // else if(sensor > 3.1){
Jesse Baker 5:d3dfaed9fd93 59 // led1 = 1;
Jesse Baker 5:d3dfaed9fd93 60 // led2 = 1;
Jesse Baker 5:d3dfaed9fd93 61 // led3 = 1;
Jesse Baker 5:d3dfaed9fd93 62 // led4 = 1;
Jesse Baker 5:d3dfaed9fd93 63 // }
Jesse Baker 5:d3dfaed9fd93 64 // else{
Jesse Baker 5:d3dfaed9fd93 65 // led1 = 0;
Jesse Baker 5:d3dfaed9fd93 66 // led2 = 0;
Jesse Baker 5:d3dfaed9fd93 67 // led3 = 0;
Jesse Baker 5:d3dfaed9fd93 68 // led4 = 0;
Jesse Baker 5:d3dfaed9fd93 69 // }
Jesse Baker 5:d3dfaed9fd93 70
Jesse Baker 5:d3dfaed9fd93 71 pc.printf("%f", sensor);
Jesse Baker 5:d3dfaed9fd93 72 wait(.5);
Jesse Baker 5:d3dfaed9fd93 73 }
Jesse Baker 5:d3dfaed9fd93 74 }