Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Fork of p2_analogin by
hello.cpp
- Committer:
- Sersd
- Date:
- 2015-09-29
- Revision:
- 0:00529fca1abf
File content as of revision 0:00529fca1abf:
// Flash an LED while a DigitalIn is true #include "mbed.h" AnalogIn ain(p15); Serial pc(USBTX, USBRX); // tx, rx float media=0; float alpha=0.99; float actual=0; float offset=0.001; int contador=0; char state =0; char prev_state=0; int timeini; int timefi; Timer timer; int main() { media= ain.read(); timer.start(); while(1) { actual=ain; // pc.printf("actual %f \n\r",actual); // pc.printf("media %f \n\r",media); media=media*alpha+(1-alpha)*actual; if((actual-media) > offset){ state=1; if(prev_state==0){ if(contador==0){ timeini = timer.read_us(); contador++; }else if(contador==1){ timefi = timer.read_us(); pc.printf("Periode %d \n\r",timefi-timeini); contador=0; } } }else if((actual-media) < offset){ state=0; } prev_state = state; wait(0.0002); } }