test reed switch for bike cadence & speed

Dependencies:   mbed

Fork of Blinking Led by Icarus Sensors

main.cpp

Committer:
balczezzz
Date:
2015-04-28
Revision:
4:1b63302b4008
Parent:
3:65d6deb7d07b
Child:
5:af96df45a447

File content as of revision 4:1b63302b4008:

#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() {
    //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                         
    }
}