/elec/propeller-clock

To get this branch, use:
bzr branch http://bzr.ed.am/elec/propeller-clock
11 by Dan
added initial propeller clock code
1
//
2
// propeller-clock.pde
3
//
4
// A propeller clock.
5
6
void setup()
7
{
8
  // set up an interrupt handler on pin 2 to nitice fan pulses
9
  attachInterrupt( 0, fanPulseHandler, RISING );
10
  digitalWrite( 2, HIGH );
11
  
12
  // set up output pins (4 to 13) for the led array
13
  for( int a = 4; a < 14; a++ )
14
    pinMode( a, OUTPUT );
15
16
  // serial comms
17
  Serial.begin( 9600 );
18
}
19
20
// when non-zero, the time (in microseconds) of a new fan pulse that has just
21
// occurred, which means that segment drawing needs to be restarted
22
static unsigned long new_pulse_at = 0;
23
24
// interrupt handler to count the number of fan pulses
25
void fanPulseHandler()
26
{
27
  // ignore every other pulse
28
  static bool ignore = true;
29
  ignore = !ignore;
30
  if( !ignore )
31
  {
32
    // set a new pulse time
33
    new_pulse_at = micros();
34
  }
35
}
36
37
// wait until it is time to draw the next segment or a new pulse has occurred
38
void endOfSegmentDelay()
39
{
40
  while( micros() < next_segment_at && !new_pulse_at );
41
}
42
43
void loop()
44
{
45
  static int led = 4;
46
47
  unsigned long loop_start_time = micros();
48
49
  // wait till it's time to draw the next segment
50
  
51
}