test reed switch for bike cadence & speed
Dependencies: mbed
Fork of Blinking Led by
Diff: main.cpp
- Revision:
- 6:0ef5a242ed00
- Parent:
- 5:af96df45a447
- Child:
- 7:d6844dacbd2e
diff -r af96df45a447 -r 0ef5a242ed00 main.cpp --- a/main.cpp Wed Apr 29 21:58:04 2015 +0000 +++ b/main.cpp Wed Apr 29 23:00:36 2015 +0000 @@ -7,6 +7,9 @@ Timer timer1; //define timer variable unsigned int counter=0; unsigned int revMin=0; +float currentSpeed=0; +unsigned int currentTime = 0; +const float wheelDiameter=0.662; //662mm rim + 2*20mm tire put in meters void toggle(void); //function prototype @@ -25,10 +28,15 @@ led=!led; debounce.reset(); //restart timer when toggle is performed - revMin = (60*1000)/timer1.read_ms(); + currentTime=timer1.read_ms(); + revMin = (60*1000)/currentTime; + currentSpeed = ((3.14159*wheelDiameter*1000)/(currentTime))*3.6; //km.h timer1.reset(); counter = counter + 1; printf("id %i",counter); - printf(" - revs/min: %i\n",revMin); + printf(" - time: %i",currentTime); + printf(" - revs/min: %i",revMin); + printf(" - speed: %4.2f",currentSpeed); + printf(" km/h \n"); //printf("switch \n\r"); }