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

Dependencies:   mbed LSM9DS1_Library_cal

Committer:
jbaker66
Date:
Fri Feb 12 18:33:24 2016 +0000
Revision:
6:713054b45e91
Parent:
5:d3dfaed9fd93
Child:
7:ef9f3c067efd
Sharp IR Sensor completed

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
jbaker66 6:713054b45e91 40 if(sensor > 0.61){
jbaker66 6:713054b45e91 41 led1 = 1;
jbaker66 6:713054b45e91 42 led2 = 1;
jbaker66 6:713054b45e91 43 led3 = 1;
jbaker66 6:713054b45e91 44 led4 = 1;
jbaker66 6:713054b45e91 45 }
jbaker66 6:713054b45e91 46 else if(sensor > 0.46){
jbaker66 6:713054b45e91 47 led1 = 1;
jbaker66 6:713054b45e91 48 led2 = 1;
jbaker66 6:713054b45e91 49 led3 = 1;
jbaker66 6:713054b45e91 50 led4 = 0;
jbaker66 6:713054b45e91 51 }
jbaker66 6:713054b45e91 52 else if(sensor > 0.30){
jbaker66 6:713054b45e91 53 led1 = 1;
jbaker66 6:713054b45e91 54 led2 = 1;
jbaker66 6:713054b45e91 55 led3 = 0;
jbaker66 6:713054b45e91 56 led4 = 0;
jbaker66 6:713054b45e91 57 }
jbaker66 6:713054b45e91 58 else if(sensor > 0.15){
jbaker66 6:713054b45e91 59 led1 = 1;
jbaker66 6:713054b45e91 60 led2 = 0;
jbaker66 6:713054b45e91 61 led3 = 0;
jbaker66 6:713054b45e91 62 led4 = 0;
jbaker66 6:713054b45e91 63 }
jbaker66 6:713054b45e91 64 else{
jbaker66 6:713054b45e91 65 led1 = 0;
jbaker66 6:713054b45e91 66 led2 = 0;
jbaker66 6:713054b45e91 67 led3 = 0;
jbaker66 6:713054b45e91 68 led4 = 0;
jbaker66 6:713054b45e91 69 }
Jesse Baker 5:d3dfaed9fd93 70
jbaker66 6:713054b45e91 71 // pc.printf("%f\n", sensor.read());
jbaker66 6:713054b45e91 72 // wait(.5);
Jesse Baker 5:d3dfaed9fd93 73 }
Jesse Baker 5:d3dfaed9fd93 74 }