![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
tp_iot
Dependencies: mbed DHT HC_SR04_Ultrasonic_Library
main.cpp@0:911000364564, 2017-05-24 (annotated)
- Committer:
- Cornetin
- Date:
- Wed May 24 12:50:09 2017 +0000
- Revision:
- 0:911000364564
- Child:
- 1:fdbb495760fc
test
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Cornetin | 0:911000364564 | 1 | #include "mbed.h" |
Cornetin | 0:911000364564 | 2 | |
Cornetin | 0:911000364564 | 3 | AnalogIn analog_value(A0); |
Cornetin | 0:911000364564 | 4 | |
Cornetin | 0:911000364564 | 5 | DigitalOut led(LED1); |
Cornetin | 0:911000364564 | 6 | |
Cornetin | 0:911000364564 | 7 | int main() { |
Cornetin | 0:911000364564 | 8 | float meas; |
Cornetin | 0:911000364564 | 9 | |
Cornetin | 0:911000364564 | 10 | printf("\nAnalogIn example\n"); |
Cornetin | 0:911000364564 | 11 | |
Cornetin | 0:911000364564 | 12 | while(1) { |
Cornetin | 0:911000364564 | 13 | meas = analog_value.read(); // Converts and read the analog input value (value from 0.0 to 1.0) |
Cornetin | 0:911000364564 | 14 | meas = meas * 3300; // Change the value to be in the 0 to 3300 range |
Cornetin | 0:911000364564 | 15 | printf("measure = %.0f mV\n", meas); |
Cornetin | 0:911000364564 | 16 | if (meas > 2000) { // If the value is greater than 2V then switch the LED on |
Cornetin | 0:911000364564 | 17 | led = 1; |
Cornetin | 0:911000364564 | 18 | } |
Cornetin | 0:911000364564 | 19 | else { |
Cornetin | 0:911000364564 | 20 | led = 0; |
Cornetin | 0:911000364564 | 21 | } |
Cornetin | 0:911000364564 | 22 | wait(0.2); // 200 ms |
Cornetin | 0:911000364564 | 23 | } |
Cornetin | 0:911000364564 | 24 | } |