Supachai Vorapojpisut
/
le484_2016
Course project for LE484 at Thammasat University, class of 2016
sensorTask.cpp@7:d702abfe51e3, 2017-05-08 (annotated)
- Committer:
- 3ecauz
- Date:
- Mon May 08 04:42:04 2017 +0000
- Revision:
- 7:d702abfe51e3
- Child:
- 8:12d666d1afb4
SensorTask update
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
3ecauz | 7:d702abfe51e3 | 1 | #include "mbed.h" |
3ecauz | 7:d702abfe51e3 | 2 | #include "platform.h" |
3ecauz | 7:d702abfe51e3 | 3 | |
3ecauz | 7:d702abfe51e3 | 4 | AnalogIn analog_value(A0); |
3ecauz | 7:d702abfe51e3 | 5 | DigitalOut led(LED1); |
3ecauz | 7:d702abfe51e3 | 6 | |
3ecauz | 7:d702abfe51e3 | 7 | void sensorIn() { |
3ecauz | 7:d702abfe51e3 | 8 | float meas; |
3ecauz | 7:d702abfe51e3 | 9 | |
3ecauz | 7:d702abfe51e3 | 10 | while(1) { |
3ecauz | 7:d702abfe51e3 | 11 | meas = analog_value.read(); |
3ecauz | 7:d702abfe51e3 | 12 | meas = meas * 3300; |
3ecauz | 7:d702abfe51e3 | 13 | printf("measure = %.0f mV\n", meas); |
3ecauz | 7:d702abfe51e3 | 14 | if (meas > 2000){ |
3ecauz | 7:d702abfe51e3 | 15 | led = 1; |
3ecauz | 7:d702abfe51e3 | 16 | } |
3ecauz | 7:d702abfe51e3 | 17 | else |
3ecauz | 7:d702abfe51e3 | 18 | led = 0; |
3ecauz | 7:d702abfe51e3 | 19 | wait(0.2); |
3ecauz | 7:d702abfe51e3 | 20 | } |
3ecauz | 7:d702abfe51e3 | 21 | } |