/elec/propeller-clock

To get this branch, use:
bzr branch http://bzr.ed.am/elec/propeller-clock
9 by Dan
Added fantest project
1
void setup()
2
{
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
7
  // current).
8
  attachInterrupt( 0, rpmCounter, RISING );
9
  digitalWrite( 2, HIGH );
10
  
11
  // init serial comms
12
  Serial.begin( 9600 );
13
}
14
15
static unsigned long fan_rotations = 0;
16
17
void rpmCounter()
18
{
19
  fan_rotations++;
20
}
21
22
void loop()
23
{
24
  // get milliseconds
25
  unsigned long start_millis = millis();
26
    
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 );
33
  fan_rotations = 0;
34
    
35
  // wait until the remainer of a second has elapsed
36
  delay( start_millis + 1000 - millis() );
37
}