Chris Clark / Mbed 2 deprecated myworld

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "math.h"
00003 DigitalOut gnd3(p15);
00004 DigitalOut gnd(p17);
00005 DigitalOut gnd1(p18);
00006 DigitalOut gnd2(p20);
00007 DigitalOut myled(LED1);
00008 DigitalOut myled2(LED2);
00009 AnalogIn mic(p16);
00010 AnalogIn photo(p15);
00011 AnalogIn Sensor(p19);
00012 Serial pc(USBTX, USBRX);
00013 
00014 
00015 
00016 float weathervalue() {
00017 
00018 float analog1;
00019 float photo1;
00020 float averageanal = 0;
00021 float averagelight = 0;
00022 
00023     for(int i = 0; i < 10; ++i)
00024     {
00025         analog1 = 20*log10(2.4/mic.read()/4096);//this is with a non normalized voltage (4096 steps of .000244) need to fix this. 
00026         /*This last line should have normalized it but it did not work.  The mic will range from 0-1 in 4096 steps of .000244.  So I 
00027         divided 2.4 by the value which should set it into our correct range (0-2.4 V) and then divided it by 4096 to get the voltage 
00028         with reference to our range. Then I took the log of that to get the decibel value.  But it was outputting very little change 
00029         in the range with noise or no noise sooo.... i need sleep. */ 
00030         photo1 = photo.read();//range of 0-1
00031         averagelight += photo1;
00032         averageanal += analog1;
00033         pc.printf("Instantaneous voltage = %f\r\nInstantaneous Light = %f\r\n", analog1, photo1);
00034         wait(.1);
00035     }
00036     
00037     averageanal = averageanal / 10;//this will give us the average voltage over the last second.
00038     averagelight = averagelight * 24 * 2.4;//this gives us the irradiance in uW/cm^2
00039     pc.printf("Average light over the last sec: %f uW/cm^2\r\n", averagelight);
00040 return averageanal;
00041 }
00042         
00043 int main() {
00044 float yo_momma;
00045 
00046     while(1) {
00047         
00048         myled = 0;
00049         myled2 = 1;
00050         yo_momma = weathervalue();
00051         pc.printf("Average over last 1 sec: %f dB\r\n", yo_momma);
00052         wait(1);
00053         myled = 1;
00054         myled2 = 0;
00055         wait(1);
00056     }
00057 }