bayern

Dependencies:   mbed DHT22

Committer:
svupper
Date:
Wed Jan 16 12:45:50 2019 +0000
Revision:
1:cfd64ae75009
Parent:
0:76148ffba877
bayern

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Sidibe 0:76148ffba877 1 #include "mbed.h"
Sidibe 0:76148ffba877 2 #include <iostream>
svupper 1:cfd64ae75009 3 #include "DHT22.h"
svupper 1:cfd64ae75009 4 #include "string.h"
svupper 1:cfd64ae75009 5
Sidibe 0:76148ffba877 6 using namespace std;
Sidibe 0:76148ffba877 7
svupper 1:cfd64ae75009 8 Serial pc(USBTX, USBRX, 9600);
svupper 1:cfd64ae75009 9 DHT22 dht22(D3);
svupper 1:cfd64ae75009 10
svupper 1:cfd64ae75009 11 //Serial device(PA_6, PA_7);
svupper 1:cfd64ae75009 12 //Serial device(A7, A2);
svupper 1:cfd64ae75009 13 //Serial device(PB_6, PB_7);
svupper 1:cfd64ae75009 14 //Serial device(PB_7, PB_6);
svupper 1:cfd64ae75009 15 Serial device(PA_9, PA_10);
svupper 1:cfd64ae75009 16 //Serial device(PA_2, PA_15);
svupper 1:cfd64ae75009 17 //SoftSerial device(PA_4, PA_5);
svupper 1:cfd64ae75009 18 //SoftSerial_IR device(PB_6, PB_7);
Sidibe 0:76148ffba877 19 //Serial sc2(D5, D4);
Sidibe 0:76148ffba877 20
svupper 1:cfd64ae75009 21 void test(){
svupper 1:cfd64ae75009 22 pc.printf("---New Call ---\r\n");
svupper 1:cfd64ae75009 23
svupper 1:cfd64ae75009 24 if(device.writeable()) {
svupper 1:cfd64ae75009 25 pc.printf("Device writeable\r\n");
svupper 1:cfd64ae75009 26 }
Sidibe 0:76148ffba877 27
svupper 1:cfd64ae75009 28 /* Debut Test Communication*/
Sidibe 0:76148ffba877 29
Sidibe 0:76148ffba877 30 device.printf("AT\r");
Sidibe 0:76148ffba877 31
svupper 1:cfd64ae75009 32 }
Sidibe 0:76148ffba877 33
svupper 1:cfd64ae75009 34 void read(){
svupper 1:cfd64ae75009 35 char temp;
svupper 1:cfd64ae75009 36 do{
svupper 1:cfd64ae75009 37 temp = device.getc();
svupper 1:cfd64ae75009 38 pc.printf("%c", temp);
svupper 1:cfd64ae75009 39 }while(temp != ';');
svupper 1:cfd64ae75009 40 }
Sidibe 0:76148ffba877 41
svupper 1:cfd64ae75009 42 void send(char c[]){
svupper 1:cfd64ae75009 43
Sidibe 0:76148ffba877 44 char donnee[] = "AT$SF=";
svupper 1:cfd64ae75009 45 strcat(donnee,c);
svupper 1:cfd64ae75009 46 strcat(donnee,"\r");
Sidibe 0:76148ffba877 47 device.printf(donnee);
svupper 1:cfd64ae75009 48 pc.printf(donnee);
svupper 1:cfd64ae75009 49 }
Sidibe 0:76148ffba877 50
svupper 1:cfd64ae75009 51 int main() {
svupper 1:cfd64ae75009 52 int humidite;
svupper 1:cfd64ae75009 53 int temperature;
svupper 1:cfd64ae75009 54 char c[] = "fff";
svupper 1:cfd64ae75009 55 device.baud(9600);
svupper 1:cfd64ae75009 56
svupper 1:cfd64ae75009 57 test();
svupper 1:cfd64ae75009 58 read();
Sidibe 0:76148ffba877 59
Sidibe 0:76148ffba877 60 while(1) {
svupper 1:cfd64ae75009 61
svupper 1:cfd64ae75009 62 dht22.sample() ;
svupper 1:cfd64ae75009 63 humidite=dht22.getHumidity()/10.0;
svupper 1:cfd64ae75009 64 temperature=dht22.getTemperature()/10.0;
svupper 1:cfd64ae75009 65 pc.printf("temperature: %d humidity: %d\n\r",temperature,humidite);
svupper 1:cfd64ae75009 66
svupper 1:cfd64ae75009 67 wait(1);
svupper 1:cfd64ae75009 68
svupper 1:cfd64ae75009 69 //char c = humidite+'0';
svupper 1:cfd64ae75009 70
svupper 1:cfd64ae75009 71 send(c);
svupper 1:cfd64ae75009 72 wait(100.0);
svupper 1:cfd64ae75009 73
Sidibe 0:76148ffba877 74 }
Sidibe 0:76148ffba877 75 }
Sidibe 0:76148ffba877 76
svupper 1:cfd64ae75009 77