Philip Timson
/
Analog_Threshold_Detector
Simple program to set a detect LED for an analog signal input larger than a threshold.
main.cpp@0:2d75e8930b10, 2010-08-15 (annotated)
- Committer:
- philiptimson
- Date:
- Sun Aug 15 00:51:29 2010 +0000
- Revision:
- 0:2d75e8930b10
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
philiptimson | 0:2d75e8930b10 | 1 | #include "mbed.h" |
philiptimson | 0:2d75e8930b10 | 2 | |
philiptimson | 0:2d75e8930b10 | 3 | DigitalOut detect(LED1); |
philiptimson | 0:2d75e8930b10 | 4 | DigitalOut peaked(LED2); |
philiptimson | 0:2d75e8930b10 | 5 | AnalogIn signal(p20); |
philiptimson | 0:2d75e8930b10 | 6 | #define threshold 0.5 |
philiptimson | 0:2d75e8930b10 | 7 | #define peak 0.99 |
philiptimson | 0:2d75e8930b10 | 8 | |
philiptimson | 0:2d75e8930b10 | 9 | int main() { |
philiptimson | 0:2d75e8930b10 | 10 | while (1) { |
philiptimson | 0:2d75e8930b10 | 11 | printf("%f\n", signal.read()); |
philiptimson | 0:2d75e8930b10 | 12 | if (signal.read() > threshold) detect=1; //turn on detect LED if the signal is greater than the threshold |
philiptimson | 0:2d75e8930b10 | 13 | else {detect=0;} |
philiptimson | 0:2d75e8930b10 | 14 | if (signal.read() > peak) peaked=1; // turn on peaked LED if the signal is too high |
philiptimson | 0:2d75e8930b10 | 15 | else peaked = 0; |
philiptimson | 0:2d75e8930b10 | 16 | wait(0.01); |
philiptimson | 0:2d75e8930b10 | 17 | } |
philiptimson | 0:2d75e8930b10 | 18 | } |