![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Proof of concept for distance and temperature monitoring
Dependencies: mbed mbedConnectorInterface mbedEndpointNetwork
main.cpp@0:cb422b231ea5, 2015-05-01 (annotated)
- Committer:
- Luminoscity
- Date:
- Fri May 01 23:21:36 2015 +0000
- Revision:
- 0:cb422b231ea5
- Child:
- 1:2d8c4995c5bc
Demo Temp and Distance Program;
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 | |
Luminoscity | 0:cb422b231ea5 | 12 | int main() { |
Luminoscity | 0:cb422b231ea5 | 13 | GroveTempSensor tempS; |
Luminoscity | 0:cb422b231ea5 | 14 | float temperature; |
Luminoscity | 0:cb422b231ea5 | 15 | unsigned int distance; |
Luminoscity | 0:cb422b231ea5 | 16 | |
Luminoscity | 0:cb422b231ea5 | 17 | while (1) { |
Luminoscity | 0:cb422b231ea5 | 18 | temperature = tempS.getTemp() * 3.0 / 5.0; |
Luminoscity | 0:cb422b231ea5 | 19 | term.printf("Temp: %0.1f\n\r", temperature); |
Luminoscity | 0:cb422b231ea5 | 20 | if (temperature > FIRE_THRESH) { |
Luminoscity | 0:cb422b231ea5 | 21 | term.printf(" OMG! THE TRASH CAN CAN IS TOTALLY ON FIRE!!\n\r"); |
Luminoscity | 0:cb422b231ea5 | 22 | } |
Luminoscity | 0:cb422b231ea5 | 23 | |
Luminoscity | 0:cb422b231ea5 | 24 | distS.start(); |
Luminoscity | 0:cb422b231ea5 | 25 | wait_ms(500); |
Luminoscity | 0:cb422b231ea5 | 26 | distance = distS.get_dist_cm(); |
Luminoscity | 0:cb422b231ea5 | 27 | term.printf("Distance: %d\n\r", distance); |
Luminoscity | 0:cb422b231ea5 | 28 | } |
Luminoscity | 0:cb422b231ea5 | 29 | } |