bike datalogging basic
Embed:
(wiki syntax)
Show/hide line numbers
Data.cpp
00001 #include "mbed.h" 00002 #include "Data.h" 00003 #define Period 1 //5000ms 00004 #define PPR 1 00005 #define periphery 2.233168 //periphery of the wheel, in this example a 28" wheel. 00006 00007 00008 00009 int count; 00010 time_t StartTime; 00011 double distance; 00012 double lastDistance; 00013 int lastCount; 00014 00015 void interval(void){ 00016 lastDistance = count * periphery / PPR; 00017 distance += lastDistance; 00018 lastCount = count; 00019 count = 0; 00020 } 00021 00022 void pressed(void){ 00023 count++; 00024 } 00025 00026 Data::Data(PinName pin) : button(pin){ 00027 StartTime = time(NULL); 00028 count = 0; 00029 distance = 0; 00030 tick.attach(interval,Period); 00031 button.fall(pressed); 00032 } 00033 00034 double Data::getDistance(void){ 00035 return distance; 00036 } 00037 00038 int Data::getTime(void){ 00039 return time(NULL) - StartTime; 00040 } 00041 00042 double Data::getSpeed(void){ 00043 return lastDistance/Period * 3.6; 00044 } 00045 00046 double Data::getAverage(void){ 00047 return distance/(time(NULL) - StartTime) * 3.6; 00048 } 00049 00050 int Data::getLastCount(void){ 00051 return lastCount; 00052 }
Generated on Fri Jul 22 2022 00:59:04 by
1.7.2