Skip to content

Instantly share code, notes, and snippets.

@maxhawkins
Created March 30, 2010 18:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maxhawkins/ee80daf80eaa404bedd9 to your computer and use it in GitHub Desktop.
Save maxhawkins/ee80daf80eaa404bedd9 to your computer and use it in GitHub Desktop.
#include <FreqCounter.h>
void setup() {
Serial.begin(9600);
}
unsigned long frq;
void loop() {
// Initialize the frequency counter on pin 5
// Read from counter every 250ms to see how many pulses there are from the fan
FreqCounter::start(250);
// Idle until the 250ms have elapsed
while (FreqCounter::f_ready == 0)
// Convert frequency into unsigned long for serial transport
frq = FreqCounter::f_freq;
// Since our sensor values are less than 256, we send only the first 8 bits
frq = frq & 0xff;
// Send first 8 bits of frequency reading as byte over serial
Serial.print(frq, BYTE);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment