/elec/propeller-clock

To get this branch, use:
bzr branch http://bzr.ed.am/elec/propeller-clock

« back to all changes in this revision

Viewing changes to fan-test/fan-test.pde

  • Committer: edam
  • Date: 2011-11-04 00:49:57 UTC
  • Revision ID: edam@waxworlds.org-20111104004957-6lv2138atk3y3519
added electronics info and (unfinished) scematic and changed Notes to
be a text file

Show diffs side-by-side

added added

removed removed

1
 
// fan_test.pde
2
 
//
3
 
// This is a test program to see if we can read the RPM speed of a PC fan.
4
 
// To set up, the fan should have an independent 12V poer supply, and the
5
 
// fan's SENSE techiometer pin should be connnected to the Arduino's pin 2.
6
 
// The RPM is sent back via serial (over USB).
7
 
 
8
 
void setup()
9
 
{
10
 
  // set up interupt 0 (which is pin 2) and turn on the pull-up resistor as we
11
 
  // would if the pin had been set to be an input. This is so that when the
12
 
  // switch on the pin is open, it is not a floatin signal and has 5V across it
13
 
  // (albeit through a high-resitance resistor to heavily constricy the
14
 
  // current).
15
 
  attachInterrupt( 0, rpmCounter, RISING );
16
 
  digitalWrite( 2, HIGH );
17
 
  
18
 
  // init serial comms
19
 
  Serial.begin( 9600 );
20
 
}
21
 
 
22
 
static unsigned long fan_rotations = 0;
23
 
 
24
 
void rpmCounter()
25
 
{
26
 
  fan_rotations++;
27
 
}
28
 
 
29
 
void loop()
30
 
{
31
 
  // get milliseconds
32
 
  unsigned long start_millis = millis();
33
 
    
34
 
  // display fan speed. We divide by 2 because the fan's "sense" pin actually
35
 
  // pulses twice per revolution. We multiply by 60 because fan_rotations will
36
 
  // have counted the number of rotations in a second and we want RPM.
37
 
//  Serial.println( fan_rotations );
38
 
  Serial.print( "RPM: " );
39
 
  Serial.println( fan_rotations / 2 * 60 );
40
 
  fan_rotations = 0;
41
 
    
42
 
  // wait until the remainer of a second has elapsed
43
 
  delay( start_millis + 1000 - millis() );
44
 
}