Simple program to set a detect LED for an analog signal input larger than a threshold.
Embed:
(wiki syntax)
Show/hide line numbers
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 }
Generated on Sun Jul 24 2022 05:44:10 by
1.7.2