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

Dependencies:   mbed LSM9DS1_Library_cal

Jesses_Lab2/Jesses_Main.cpp

Committer:
jbaker66
Date:
2016-02-12
Revision:
6:713054b45e91
Parent:
5:d3dfaed9fd93
Child:
7:ef9f3c067efd

File content as of revision 6:713054b45e91:

// <- remove this if you want to code this and comment Georges
#include "mbed.h"

// --------------------------------------------------------------------------------

//// AnalogOut sine wave complete
//AnalogOut aout(p18);
//
//int main(){
//    const double pi = 3.141592653589793238462;
//    const double amplitude = 1;
//    const double offset = 65535/2;
//    double rads = 0.0;
//    uint16_t sample = 0;
//
//    while(1){
//        // sinewave output
//        for (int i = 0; i < 360; i++) {
//            rads = (pi * i) / 180.0f;
//            sample = (uint16_t)(amplitude * (offset * (cos(rads + pi))) + offset);
//            aout.write_u16(sample);
//        }
//    }
//}
// --------------------------------------------------------------------------------

// Sharp IR sensor

Serial pc(USBTX, USBRX);

AnalogIn sensor(p15);
DigitalOut led1(LED1);
DigitalOut led2(LED2);
DigitalOut led3(LED3);
DigitalOut led4(LED4);

int main(){
  while(1){

     if(sensor > 0.61){
       led1 = 1;
       led2 = 1;
       led3 = 1;
       led4 = 1;
     }
     else if(sensor > 0.46){
       led1 = 1;
       led2 = 1;
       led3 = 1;
       led4 = 0;
     }
     else if(sensor > 0.30){
       led1 = 1;
       led2 = 1;
       led3 = 0;
       led4 = 0;
     }
     else if(sensor > 0.15){
       led1 = 1;
       led2 = 0;
       led3 = 0;
       led4 = 0;
     }
     else{
       led1 = 0;
       led2 = 0;
       led3 = 0;
       led4 = 0;
     }

//    pc.printf("%f\n", sensor.read());
//    wait(.5);
  }
}