test reed switch for bike cadence & speed

Dependencies:   mbed

Fork of Blinking Led by Icarus Sensors

Committer:
balczezzz
Date:
Tue Apr 28 06:25:30 2015 +0000
Revision:
4:1b63302b4008
Parent:
3:65d6deb7d07b
Child:
5:af96df45a447
test_reed_switch:; - led blinking; - serial printf; - counting

Who changed what in which revision?

UserRevisionLine numberNew contents of line
smigielski 0:b729782a3ad7 1 #include "mbed.h"
smigielski 0:b729782a3ad7 2
balczezzz 4:1b63302b4008 3 #define BAUD_RATE 9600 //default baud rate
smigielski 2:c76222c6370a 4 DigitalOut led(LED1); //P0_18 in NRF51822_MKIT
balczezzz 4:1b63302b4008 5 DigitalIn reed_speed(p1, PullDown); //P0_01 in NRF51822_MKIT
balczezzz 4:1b63302b4008 6 unsigned int counter=0;
smigielski 0:b729782a3ad7 7
smigielski 0:b729782a3ad7 8 int main() {
balczezzz 4:1b63302b4008 9 //Configure boud rate
balczezzz 4:1b63302b4008 10 Serial s(USBTX, USBRX); //default for nrf51 is p0.09 p0.11
balczezzz 4:1b63302b4008 11 s.baud(BAUD_RATE);
balczezzz 4:1b63302b4008 12 counter = 0;
balczezzz 4:1b63302b4008 13
balczezzz 4:1b63302b4008 14 while(1) {
balczezzz 4:1b63302b4008 15 if (reed_speed) {
balczezzz 4:1b63302b4008 16 counter = counter + 1;
balczezzz 4:1b63302b4008 17 led = 1; // LED is ON
balczezzz 4:1b63302b4008 18 printf("number of revs: %i\n",counter);
balczezzz 4:1b63302b4008 19 while(reed_speed){ //display dots to check if counting works
balczezzz 4:1b63302b4008 20 printf(".");
balczezzz 4:1b63302b4008 21 }
balczezzz 4:1b63302b4008 22
balczezzz 4:1b63302b4008 23 }
balczezzz 4:1b63302b4008 24 else {
balczezzz 4:1b63302b4008 25 led = 0; //LED is OFF
balczezzz 4:1b63302b4008 26 }
balczezzz 4:1b63302b4008 27 wait(0.100); // 100 ms
smigielski 0:b729782a3ad7 28 }
balczezzz 4:1b63302b4008 29 }