luis velasco
/
red
ESCLAVO EN COMUNICACIÓN RF MEDIANTE XBEE
main.cpp@0:a9edb2087606, 2017-06-03 (annotated)
- Committer:
- Luisv
- Date:
- Sat Jun 03 16:03:58 2017 +0000
- Revision:
- 0:a9edb2087606
ESCLAVO
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Luisv | 0:a9edb2087606 | 1 | //ESCLAVO// |
Luisv | 0:a9edb2087606 | 2 | #include "mbed.h" |
Luisv | 0:a9edb2087606 | 3 | #include "DHT.h" |
Luisv | 0:a9edb2087606 | 4 | #include <string> |
Luisv | 0:a9edb2087606 | 5 | |
Luisv | 0:a9edb2087606 | 6 | Serial pc(USBTX,USBRX); |
Luisv | 0:a9edb2087606 | 7 | Serial TxRx(D14, D15); |
Luisv | 0:a9edb2087606 | 8 | DHT sensor(D4, DHT11); |
Luisv | 0:a9edb2087606 | 9 | DigitalOut Reset(A2); |
Luisv | 0:a9edb2087606 | 10 | |
Luisv | 0:a9edb2087606 | 11 | float medida, sens, sens1; |
Luisv | 0:a9edb2087606 | 12 | char humedad[10], temp[10]; |
Luisv | 0:a9edb2087606 | 13 | char r1[125], r2[125]; |
Luisv | 0:a9edb2087606 | 14 | string Texto1, Texto2; |
Luisv | 0:a9edb2087606 | 15 | |
Luisv | 0:a9edb2087606 | 16 | int main() |
Luisv | 0:a9edb2087606 | 17 | { |
Luisv | 0:a9edb2087606 | 18 | Reset = 0; |
Luisv | 0:a9edb2087606 | 19 | wait(0.1); |
Luisv | 0:a9edb2087606 | 20 | Reset = 1; |
Luisv | 0:a9edb2087606 | 21 | |
Luisv | 0:a9edb2087606 | 22 | pc.printf("Esclavo Invocado\n\r"); |
Luisv | 0:a9edb2087606 | 23 | while(1) |
Luisv | 0:a9edb2087606 | 24 | { |
Luisv | 0:a9edb2087606 | 25 | medida=sensor.readData(); |
Luisv | 0:a9edb2087606 | 26 | sens = sensor.ReadHumidity(); |
Luisv | 0:a9edb2087606 | 27 | sens1 = sensor.ReadTemperature(CELCIUS); |
Luisv | 0:a9edb2087606 | 28 | sprintf(temp,"%.2f",sens1); |
Luisv | 0:a9edb2087606 | 29 | sprintf(humedad,"%.2f",sens); |
Luisv | 0:a9edb2087606 | 30 | string str1(temp); |
Luisv | 0:a9edb2087606 | 31 | string str(humedad); |
Luisv | 0:a9edb2087606 | 32 | do |
Luisv | 0:a9edb2087606 | 33 | { |
Luisv | 0:a9edb2087606 | 34 | //while(TxRx.readable() == 1) |
Luisv | 0:a9edb2087606 | 35 | { |
Luisv | 0:a9edb2087606 | 36 | Texto1 = ""; |
Luisv | 0:a9edb2087606 | 37 | TxRx.gets(r1,5); |
Luisv | 0:a9edb2087606 | 38 | Texto1 += r1; |
Luisv | 0:a9edb2087606 | 39 | wait(0.001); |
Luisv | 0:a9edb2087606 | 40 | } |
Luisv | 0:a9edb2087606 | 41 | }while(Texto1 == ""); |
Luisv | 0:a9edb2087606 | 42 | if(Texto1 =="0033") |
Luisv | 0:a9edb2087606 | 43 | { |
Luisv | 0:a9edb2087606 | 44 | pc.printf("Enviando....\n\r"); |
Luisv | 0:a9edb2087606 | 45 | TxRx.printf("%s\n",str1); |
Luisv | 0:a9edb2087606 | 46 | wait(0.1); |
Luisv | 0:a9edb2087606 | 47 | TxRx.printf("%s\n",str); |
Luisv | 0:a9edb2087606 | 48 | pc.printf("temperatura:%s\n\r",str1); |
Luisv | 0:a9edb2087606 | 49 | pc.printf("humedad:%s\n\r",str); |
Luisv | 0:a9edb2087606 | 50 | } |
Luisv | 0:a9edb2087606 | 51 | Texto1 = ""; |
Luisv | 0:a9edb2087606 | 52 | } |
Luisv | 0:a9edb2087606 | 53 | } |