hisyam fs / Mbed 2 deprecated LineInterrupt

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 InterruptIn line(PA_0);
00004 Timer timer;
00005 volatile float dur = 0.0f;
00006 int printed = 0;
00007 
00008 void start() {
00009     timer.reset();
00010     timer.start();
00011 }
00012 
00013 void end() {
00014     timer.stop();
00015     dur = timer.read();   
00016 }
00017 
00018 int main() {
00019     line.fall(&start);
00020     line.rise(&end);
00021     while (1) {
00022         if (!printed) {
00023             printf("%.2f\n", dur);
00024             printed = 1;
00025         }
00026         else {
00027             printed = 0;
00028         }
00029     } 
00030 }
00031