tp_iot
Dependencies: mbed DHT HC_SR04_Ultrasonic_Library
main.cpp@3:fcc03d78faf4, 2017-05-24 (annotated)
- Committer:
- Cornetin
- Date:
- Wed May 24 14:23:54 2017 +0000
- Revision:
- 3:fcc03d78faf4
- Parent:
- 2:d1555ccd1c6d
- Child:
- 4:74e0c3de6749
commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Cornetin | 0:911000364564 | 1 | #include "mbed.h" |
Cornetin | 1:fdbb495760fc | 2 | #include "Serial.h" |
Cornetin | 2:d1555ccd1c6d | 3 | #include <string> |
Cornetin | 2:d1555ccd1c6d | 4 | |
Cornetin | 1:fdbb495760fc | 5 | // WE USE PA_2 = TX } CN9 |
Cornetin | 1:fdbb495760fc | 6 | // PA_3 = RX } CN9 |
Cornetin | 1:fdbb495760fc | 7 | |
Cornetin | 0:911000364564 | 8 | |
Cornetin | 0:911000364564 | 9 | AnalogIn analog_value(A0); |
Cornetin | 0:911000364564 | 10 | |
Cornetin | 2:d1555ccd1c6d | 11 | DigitalOut led(LED2); |
Cornetin | 0:911000364564 | 12 | |
Cornetin | 0:911000364564 | 13 | int main() { |
Cornetin | 0:911000364564 | 14 | float meas; |
Cornetin | 1:fdbb495760fc | 15 | Serial serial_td1208(PA_2, PA_3); |
Cornetin | 1:fdbb495760fc | 16 | |
Cornetin | 3:fcc03d78faf4 | 17 | //std::string init("AT"); |
Cornetin | 3:fcc03d78faf4 | 18 | |
Cornetin | 3:fcc03d78faf4 | 19 | std::string query("AT$SS=00 12 FF 42/r/n"); |
Cornetin | 3:fcc03d78faf4 | 20 | |
Cornetin | 3:fcc03d78faf4 | 21 | serial_td1208.baud(9600); |
Cornetin | 3:fcc03d78faf4 | 22 | serial_td1208.format(); |
Cornetin | 3:fcc03d78faf4 | 23 | //serial_td1208.printf("%s", init); |
Cornetin | 2:d1555ccd1c6d | 24 | |
Cornetin | 0:911000364564 | 25 | |
Cornetin | 0:911000364564 | 26 | printf("\nAnalogIn example\n"); |
Cornetin | 2:d1555ccd1c6d | 27 | led = 1; |
Cornetin | 0:911000364564 | 28 | |
Cornetin | 0:911000364564 | 29 | while(1) { |
Cornetin | 2:d1555ccd1c6d | 30 | /* |
Cornetin | 0:911000364564 | 31 | meas = analog_value.read(); // Converts and read the analog input value (value from 0.0 to 1.0) |
Cornetin | 0:911000364564 | 32 | meas = meas * 3300; // Change the value to be in the 0 to 3300 range |
Cornetin | 0:911000364564 | 33 | printf("measure = %.0f mV\n", meas); |
Cornetin | 0:911000364564 | 34 | if (meas > 2000) { // If the value is greater than 2V then switch the LED on |
Cornetin | 0:911000364564 | 35 | led = 1; |
Cornetin | 0:911000364564 | 36 | } |
Cornetin | 0:911000364564 | 37 | else { |
Cornetin | 0:911000364564 | 38 | led = 0; |
Cornetin | 2:d1555ccd1c6d | 39 | }*/ |
Cornetin | 2:d1555ccd1c6d | 40 | if (led == 1) |
Cornetin | 2:d1555ccd1c6d | 41 | led = 0; |
Cornetin | 2:d1555ccd1c6d | 42 | else |
Cornetin | 2:d1555ccd1c6d | 43 | led = 1; |
Cornetin | 3:fcc03d78faf4 | 44 | |
Cornetin | 3:fcc03d78faf4 | 45 | //serial_rd1208.write(query.c_str(), query.length(), ); |
Cornetin | 2:d1555ccd1c6d | 46 | serial_td1208.printf("%s", query); |
Cornetin | 2:d1555ccd1c6d | 47 | wait(10); // 750 ms |
Cornetin | 0:911000364564 | 48 | } |
Cornetin | 0:911000364564 | 49 | } |