Created
December 11, 2019 15:27
-
-
Save kenbarbour/080a5522076867144ed2f9728354b610 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "windspeed.h" | |
/** | |
* Interrupt Service Routine to run when a hall effect sensor triggers a rising interrupt | |
*/ | |
void windspeed_isr(void) | |
{ | |
windspeed_revs++; | |
} | |
/** | |
* Returns the average rpm since the last call to get_windspeed_avg_rpm | |
*/ | |
float get_windspeed_avg_rpm() | |
{ | |
unsigned long now = millis(); | |
unsigned long elapsed = now - windspeed_last; | |
float rpm = (float) windspeed_revs / (float) elapsed * 60000; | |
windspeed_last = now; | |
windspeed_revs = 0; | |
return rpm; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef _WINDSPEED_H_ | |
#define _WINDSPEED_H_ | |
unsigned long windspeed_last = 0; | |
unsigned int windspeed_revs = 0; | |
void windspeed_isr(void); | |
void get_windspeed_avg_rpm(); | |
#endif /** _WINDSPEED_H_ include guard **/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment