timer tests with the STM32F303K8 nucleo board

Dependencies:   mbed

main.cpp

Committer:
OliverKeller
Date:
2016-06-10
Revision:
0:e40146aa84f7

File content as of revision 0:e40146aa84f7:

#include "mbed.h"

Timer t;
int rise_time = 0;
int fall_time = 0;
bool new_rise = false;
bool new_fall = false;

void pin_up(){
    rise_time=t.read_us();
    new_rise=true;
}

void pin_down(){
    fall_time=t.read_us();
    new_fall=true;
}

Serial pc(USBTX, USBRX);
 
int main() {
     pc.baud(230400);
     t.start();
     InterruptIn _interrupt(D1);
     _interrupt.rise(&pin_up);
     _interrupt.fall(&pin_down);
    pc.printf("Hello World!");
    while(1) {
        if(new_rise && new_fall) {
            pc.printf("%d\n\r", fall_time - rise_time);
            new_rise=false;
            new_fall=false;
        }
    }
}