TestMic

Dependencies:   DHT mbed

Committer:
NicklasNp
Date:
Wed Apr 12 12:16:17 2017 +0000
Revision:
1:b7c5a1dba0c3
Parent:
0:ff359bd0a096
added commenting

Who changed what in which revision?

UserRevisionLine numberNew contents of line
elt14lpo 0:ff359bd0a096 1 #include<stdio.h>
NicklasNp 1:b7c5a1dba0c3 2 #include<AnalogIn.h> //Library for using analog inputs
NicklasNp 1:b7c5a1dba0c3 3 #include<mbed.h> //Regular mbed library
NicklasNp 1:b7c5a1dba0c3 4 #include<DHT.h> //Library for Humidity/temperature sensor, the only one that works.
elt14lpo 0:ff359bd0a096 5
elt14lpo 0:ff359bd0a096 6 AnalogIn mic1(A0);
elt14lpo 0:ff359bd0a096 7 AnalogIn mic2(A1);
elt14lpo 0:ff359bd0a096 8 AnalogIn mic3(A2);
elt14lpo 0:ff359bd0a096 9 DHT sensor(A3, DHT11);
elt14lpo 0:ff359bd0a096 10
elt14lpo 0:ff359bd0a096 11 const int n = 100;
elt14lpo 0:ff359bd0a096 12 int m1[n];
elt14lpo 0:ff359bd0a096 13 int m2[n];
elt14lpo 0:ff359bd0a096 14 int m3[n];
elt14lpo 0:ff359bd0a096 15 int data;
elt14lpo 0:ff359bd0a096 16
elt14lpo 0:ff359bd0a096 17 int main(){
elt14lpo 0:ff359bd0a096 18 for(int i = 0; i<n; ++i){
elt14lpo 0:ff359bd0a096 19 float f1 = 10*mic1.read();
elt14lpo 0:ff359bd0a096 20 float f2 = 10*mic2.read();
elt14lpo 0:ff359bd0a096 21 float f3 = 10*mic3.read();
elt14lpo 0:ff359bd0a096 22 printf("Mic 1: ");
elt14lpo 0:ff359bd0a096 23 printf("%10.6f",f1);
elt14lpo 0:ff359bd0a096 24 printf("\t Mic 2:");
elt14lpo 0:ff359bd0a096 25 printf("%10.6f", f2);
elt14lpo 0:ff359bd0a096 26 printf("\t Mic 3:");
elt14lpo 0:ff359bd0a096 27 printf("%10.6f", f3);
elt14lpo 0:ff359bd0a096 28 printf("\n");
elt14lpo 0:ff359bd0a096 29 //wait(0.1);
elt14lpo 0:ff359bd0a096 30 m1[i]=f1;
elt14lpo 0:ff359bd0a096 31 m2[i]=f2;
elt14lpo 0:ff359bd0a096 32 m2[i]=f3;
elt14lpo 0:ff359bd0a096 33
elt14lpo 0:ff359bd0a096 34 data = sensor.readData();
elt14lpo 0:ff359bd0a096 35 if (data == 0){
elt14lpo 0:ff359bd0a096 36 printf("Temp: %4.2f C",sensor.ReadTemperature(CELCIUS));
elt14lpo 0:ff359bd0a096 37 printf("Hum: %4.2f",sensor.ReadHumidity());
elt14lpo 0:ff359bd0a096 38 }
elt14lpo 0:ff359bd0a096 39 printf("\n");
elt14lpo 0:ff359bd0a096 40
elt14lpo 0:ff359bd0a096 41 }
elt14lpo 0:ff359bd0a096 42 }