Skip to content

Instantly share code, notes, and snippets.

@kenbarbour
Created December 11, 2019 15:27
Show Gist options
  • Save kenbarbour/080a5522076867144ed2f9728354b610 to your computer and use it in GitHub Desktop.
Save kenbarbour/080a5522076867144ed2f9728354b610 to your computer and use it in GitHub Desktop.
#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;
}
#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