User:Zmetzing:class stuff

From Dallas Makerspace
Jump to: navigation, search
// Count the time to toggle a LED
 
#include "mbed.h"
 
Timer timer;
DigitalOut led(LED1);
DigitalIn mybutton(USER_BUTTON);
int begin, end;
int btn;
 
int main() {
    printf("Press button to start timer\r\n");
    btn = mybutton.read();
    while (mybutton.read() == btn);
    wait(0.1); // contacts are bouncing for part of this
    btn = mybutton.read();
    while (mybutton.read() == btn);  
    wait(0.1); // contacts are bouncing for part of this
    timer.start();
    begin = timer.read_us();
    printf("Press button to stop timer\r\n");
    btn = mybutton.read();
    while (mybutton.read() == btn);   
    end = timer.read_us();
    printf("Time between button presses is %d us\n\r", end - begin);
}