Venkata Arza
/
Slave_Main_tempHumid
Slave for temp k64f
Slave_Main_Temp.cpp@0:399c90b6c19a, 2018-12-12 (annotated)
- Committer:
- varza
- Date:
- Wed Dec 12 22:03:38 2018 +0000
- Revision:
- 0:399c90b6c19a
temp/humid k64f slave;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
varza | 0:399c90b6c19a | 1 | #include "mbed.h" |
varza | 0:399c90b6c19a | 2 | #include "DHT.h" |
varza | 0:399c90b6c19a | 3 | |
varza | 0:399c90b6c19a | 4 | DHT sensor(D4, DHT11); |
varza | 0:399c90b6c19a | 5 | Timeout response; |
varza | 0:399c90b6c19a | 6 | |
varza | 0:399c90b6c19a | 7 | DigitalOut green(LED_GREEN); |
varza | 0:399c90b6c19a | 8 | DigitalOut red(LED_RED); |
varza | 0:399c90b6c19a | 9 | DigitalIn sw2(SW2); |
varza | 0:399c90b6c19a | 10 | Serial pc(USBTX, USBRX ); |
varza | 0:399c90b6c19a | 11 | |
varza | 0:399c90b6c19a | 12 | Serial blue(PTC15, PTC14); //tx, rx |
varza | 0:399c90b6c19a | 13 | |
varza | 0:399c90b6c19a | 14 | int main() |
varza | 0:399c90b6c19a | 15 | { |
varza | 0:399c90b6c19a | 16 | int error = 0; |
varza | 0:399c90b6c19a | 17 | float h = 0.0f, k = 0.0f, dpf = 0.0f; |
varza | 0:399c90b6c19a | 18 | int c; |
varza | 0:399c90b6c19a | 19 | int f; |
varza | 0:399c90b6c19a | 20 | int dp; |
varza | 0:399c90b6c19a | 21 | char send = 'Z'; |
varza | 0:399c90b6c19a | 22 | char hold = 'b'; |
varza | 0:399c90b6c19a | 23 | char correct = 'C'; |
varza | 0:399c90b6c19a | 24 | int rangeFeet; |
varza | 0:399c90b6c19a | 25 | |
varza | 0:399c90b6c19a | 26 | |
varza | 0:399c90b6c19a | 27 | pc.baud(9600); |
varza | 0:399c90b6c19a | 28 | blue.baud(9600); |
varza | 0:399c90b6c19a | 29 | |
varza | 0:399c90b6c19a | 30 | printf("Slave connecting to the master\n"); |
varza | 0:399c90b6c19a | 31 | |
varza | 0:399c90b6c19a | 32 | |
varza | 0:399c90b6c19a | 33 | //------------------------Sensor Start------------------------------------- |
varza | 0:399c90b6c19a | 34 | |
varza | 0:399c90b6c19a | 35 | |
varza | 0:399c90b6c19a | 36 | while (send!='R') { |
varza | 0:399c90b6c19a | 37 | wait(0.5f); |
varza | 0:399c90b6c19a | 38 | error = sensor.readData(); |
varza | 0:399c90b6c19a | 39 | if (0 == error) |
varza | 0:399c90b6c19a | 40 | { |
varza | 0:399c90b6c19a | 41 | c = sensor.ReadTemperature(CELCIUS); |
varza | 0:399c90b6c19a | 42 | f = sensor.ReadTemperature(FARENHEIT); |
varza | 0:399c90b6c19a | 43 | k = sensor.ReadTemperature(KELVIN); |
varza | 0:399c90b6c19a | 44 | h = sensor.ReadHumidity(); |
varza | 0:399c90b6c19a | 45 | dp = sensor.CalcdewPoint(c, h); |
varza | 0:399c90b6c19a | 46 | dpf = sensor.CalcdewPointFast(c, h); |
varza | 0:399c90b6c19a | 47 | |
varza | 0:399c90b6c19a | 48 | printf("\n Temperature in Kelvin: %4.2f, Celcius: %i, Farenheit %i\n\r", k, c, f); |
varza | 0:399c90b6c19a | 49 | printf("\n Humidity is %4.2f, Dewpoint: %i, Dewpoint fast: %4.2f\n\r", h, dp, dpf); |
varza | 0:399c90b6c19a | 50 | } |
varza | 0:399c90b6c19a | 51 | else |
varza | 0:399c90b6c19a | 52 | { |
varza | 0:399c90b6c19a | 53 | // printf("Error: %d\n\r", error); |
varza | 0:399c90b6c19a | 54 | } |
varza | 0:399c90b6c19a | 55 | |
varza | 0:399c90b6c19a | 56 | |
varza | 0:399c90b6c19a | 57 | //-----------------------Sensor End-------------------------------------- |
varza | 0:399c90b6c19a | 58 | //-----------------------Transmit Begin---------------------------------- |
varza | 0:399c90b6c19a | 59 | |
varza | 0:399c90b6c19a | 60 | if(blue.readable()) |
varza | 0:399c90b6c19a | 61 | { |
varza | 0:399c90b6c19a | 62 | char word = f + '0'; |
varza | 0:399c90b6c19a | 63 | blue.putc(word); |
varza | 0:399c90b6c19a | 64 | |
varza | 0:399c90b6c19a | 65 | wait(0.5f); |
varza | 0:399c90b6c19a | 66 | |
varza | 0:399c90b6c19a | 67 | word = dp + '0'; |
varza | 0:399c90b6c19a | 68 | blue.putc(word); |
varza | 0:399c90b6c19a | 69 | } |
varza | 0:399c90b6c19a | 70 | |
varza | 0:399c90b6c19a | 71 | //----------------------Transmit End------------------------------------ |
varza | 0:399c90b6c19a | 72 | |
varza | 0:399c90b6c19a | 73 | wait(0.5f); // wait a small period of time |
varza | 0:399c90b6c19a | 74 | green = !green; // toggle a led |
varza | 0:399c90b6c19a | 75 | |
varza | 0:399c90b6c19a | 76 | } |
varza | 0:399c90b6c19a | 77 | } |
varza | 0:399c90b6c19a | 78 |