![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Proof of concept for distance and temperature monitoring
Dependencies: mbed mbedConnectorInterface mbedEndpointNetwork
main.cpp@1:2d8c4995c5bc, 2015-05-01 (annotated)
- Committer:
- coyotebush
- Date:
- Fri May 01 23:24:06 2015 +0000
- Revision:
- 1:2d8c4995c5bc
- Parent:
- 0:cb422b231ea5
- Child:
- 3:b51fcb5fd114
hi
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Luminoscity | 0:cb422b231ea5 | 1 | #include "mbed.h" |
Luminoscity | 0:cb422b231ea5 | 2 | #include "hcsr04.h" |
Luminoscity | 0:cb422b231ea5 | 3 | #include "GroveTemp.h" |
Luminoscity | 0:cb422b231ea5 | 4 | |
Luminoscity | 0:cb422b231ea5 | 5 | #define TRIG_PIN D6 |
Luminoscity | 0:cb422b231ea5 | 6 | #define ECHO_PIN D7 |
Luminoscity | 0:cb422b231ea5 | 7 | #define FIRE_THRESH 32.0 |
Luminoscity | 0:cb422b231ea5 | 8 | |
Luminoscity | 0:cb422b231ea5 | 9 | Serial term(USBTX, USBRX); |
Luminoscity | 0:cb422b231ea5 | 10 | HCSR04 distS(TRIG_PIN, ECHO_PIN); |
Luminoscity | 0:cb422b231ea5 | 11 | |
coyotebush | 1:2d8c4995c5bc | 12 | // Corey was here |
Luminoscity | 0:cb422b231ea5 | 13 | int main() { |
Luminoscity | 0:cb422b231ea5 | 14 | GroveTempSensor tempS; |
Luminoscity | 0:cb422b231ea5 | 15 | float temperature; |
Luminoscity | 0:cb422b231ea5 | 16 | unsigned int distance; |
Luminoscity | 0:cb422b231ea5 | 17 | |
Luminoscity | 0:cb422b231ea5 | 18 | while (1) { |
Luminoscity | 0:cb422b231ea5 | 19 | temperature = tempS.getTemp() * 3.0 / 5.0; |
Luminoscity | 0:cb422b231ea5 | 20 | term.printf("Temp: %0.1f\n\r", temperature); |
Luminoscity | 0:cb422b231ea5 | 21 | if (temperature > FIRE_THRESH) { |
Luminoscity | 0:cb422b231ea5 | 22 | term.printf(" OMG! THE TRASH CAN CAN IS TOTALLY ON FIRE!!\n\r"); |
Luminoscity | 0:cb422b231ea5 | 23 | } |
Luminoscity | 0:cb422b231ea5 | 24 | |
Luminoscity | 0:cb422b231ea5 | 25 | distS.start(); |
Luminoscity | 0:cb422b231ea5 | 26 | wait_ms(500); |
Luminoscity | 0:cb422b231ea5 | 27 | distance = distS.get_dist_cm(); |
Luminoscity | 0:cb422b231ea5 | 28 | term.printf("Distance: %d\n\r", distance); |
Luminoscity | 0:cb422b231ea5 | 29 | } |
Luminoscity | 0:cb422b231ea5 | 30 | } |