Philip Timson / Mbed 2 deprecated Analog_Threshold_Detector

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 
00003 DigitalOut detect(LED1);
00004 DigitalOut peaked(LED2);
00005 AnalogIn signal(p20);
00006 #define threshold 0.5
00007 #define peak 0.99
00008 
00009 int main() {
00010     while (1) {
00011         printf("%f\n", signal.read());
00012         if (signal.read() > threshold) detect=1; //turn on detect LED if the signal is greater than the threshold
00013             else {detect=0;}
00014         if (signal.read() > peak) peaked=1; // turn on peaked LED if the signal is too high
00015             else peaked = 0;
00016         wait(0.01);
00017     }
00018 }