3
// set up interupt 0 (which is pin 2) and turn on the pull-up resistor as we
4
// would if the pin had been set to be an input. This is so that when the
5
// switch on the pin is open, it is not a floatin signal and has 5V across it
6
// (albeit through a high-resitance resistor to heavily constricy the
8
attachInterrupt( 0, rpmCounter, RISING );
9
digitalWrite( 2, HIGH );
15
static unsigned long fan_rotations = 0;
25
unsigned long start_millis = millis();
27
// display fan speed. We divide by 2 because the fan's "sense" pin actually
28
// pulses twice per revolution. We multiply by 60 because fan_rotations will
29
// have counted the number of rotations in a second and we want RPM.
30
// Serial.println( fan_rotations );
31
Serial.print( "RPM: " );
32
Serial.println( fan_rotations / 2 * 60 );
35
// wait until the remainer of a second has elapsed
36
delay( start_millis + 1000 - millis() );