tp_iot

Dependencies:   mbed DHT HC_SR04_Ultrasonic_Library

Committer:
Cornetin
Date:
Mon Jun 05 22:53:33 2017 +0000
Revision:
6:cd3b177a3e33
Parent:
5:0186f7e2053e
Add support for HC SR04 now make it work;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Cornetin 0:911000364564 1 #include "mbed.h"
Cornetin 1:fdbb495760fc 2 #include "Serial.h"
Cornetin 2:d1555ccd1c6d 3 #include <string>
Cornetin 6:cd3b177a3e33 4 #include "DHT/DHT.h"
Cornetin 6:cd3b177a3e33 5 #include "HC_SR04_Ultrasonic_Library/ultrasonic.h"
Cornetin 2:d1555ccd1c6d 6
Cornetin 0:911000364564 7 AnalogIn analog_value(A0);
Cornetin 6:cd3b177a3e33 8
Cornetin 2:d1555ccd1c6d 9 DigitalOut led(LED2);
Cornetin 0:911000364564 10
Cornetin 6:cd3b177a3e33 11 int main()
Cornetin 6:cd3b177a3e33 12 {
Cornetin 6:cd3b177a3e33 13 Serial serial_td1208(PA_0, PA_1);
Cornetin 6:cd3b177a3e33 14 DHT dht11(PA_4, DHT11);
Cornetin 6:cd3b177a3e33 15 ultrasonic usensor(PA_8, PA_9, 1000, 1);
Cornetin 1:fdbb495760fc 16
Cornetin 6:cd3b177a3e33 17 //for ultrasonic we use D8,D7
Cornetin 6:cd3b177a3e33 18
Cornetin 3:fcc03d78faf4 19 serial_td1208.baud(9600);
Cornetin 3:fcc03d78faf4 20 serial_td1208.format();
Cornetin 3:fcc03d78faf4 21 //serial_td1208.printf("%s", init);
Cornetin 6:cd3b177a3e33 22
Cornetin 6:cd3b177a3e33 23 int temperature = 0, humidity = 0, distance = 0, lightlevel = 0;
Cornetin 0:911000364564 24 printf("\nAnalogIn example\n");
Cornetin 2:d1555ccd1c6d 25 led = 1;
Cornetin 0:911000364564 26 while(1) {
Cornetin 4:74e0c3de6749 27
Cornetin 2:d1555ccd1c6d 28 if (led == 1)
Cornetin 2:d1555ccd1c6d 29 led = 0;
Cornetin 2:d1555ccd1c6d 30 else
Cornetin 2:d1555ccd1c6d 31 led = 1;
Cornetin 6:cd3b177a3e33 32 //TODO: each 10 second we send the value of the DHT11
Cornetin 6:cd3b177a3e33 33 // use %08x
Cornetin 6:cd3b177a3e33 34 if (!dht11.readData()) {
Cornetin 6:cd3b177a3e33 35 temperature = static_cast<int>(dht11.ReadTemperature(CELCIUS));
Cornetin 6:cd3b177a3e33 36 humidity = static_cast<int>(dht11.ReadHumidity());
Cornetin 6:cd3b177a3e33 37 }
Cornetin 6:cd3b177a3e33 38
Cornetin 6:cd3b177a3e33 39 distance = usensor.getCurrentDistance();
Cornetin 6:cd3b177a3e33 40
Cornetin 6:cd3b177a3e33 41 serial_td1208.printf("AT$SS=%02x%02x%02x%02x\r\n", temperature, humidity, distance, lightlevel);
Cornetin 6:cd3b177a3e33 42 usensor.startUpdates();
Cornetin 6:cd3b177a3e33 43 wait(10);
Cornetin 6:cd3b177a3e33 44 usensor.pauseUpdates();
Cornetin 6:cd3b177a3e33 45
Cornetin 0:911000364564 46 }
Cornetin 0:911000364564 47 }