test reed switch for bike cadence & speed
Dependencies: mbed
Fork of Blinking Led by
Diff: main.cpp
- Revision:
- 4:1b63302b4008
- Parent:
- 3:65d6deb7d07b
- Child:
- 5:af96df45a447
--- a/main.cpp Wed Nov 19 20:57:59 2014 +0000 +++ b/main.cpp Tue Apr 28 06:25:30 2015 +0000 @@ -1,12 +1,29 @@ #include "mbed.h" +#define BAUD_RATE 9600 //default baud rate DigitalOut led(LED1); //P0_18 in NRF51822_MKIT +DigitalIn reed_speed(p1, PullDown); //P0_01 in NRF51822_MKIT +unsigned int counter=0; int main() { - while(1) { - led = 1; // LED is ON - wait(0.250); // 250 ms - led = 0; // LED is OFF - wait(0.750); // 750 ms + //Configure boud rate + Serial s(USBTX, USBRX); //default for nrf51 is p0.09 p0.11 + s.baud(BAUD_RATE); + counter = 0; + + while(1) { + if (reed_speed) { + counter = counter + 1; + led = 1; // LED is ON + printf("number of revs: %i\n",counter); + while(reed_speed){ //display dots to check if counting works + printf("."); + } + + } + else { + led = 0; //LED is OFF + } + wait(0.100); // 100 ms } -} \ No newline at end of file +}