/elec/propeller-clock

To get this branch, use:
bzr branch http://bzr.ed.am/elec/propeller-clock
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
//
// propeller-clock.pde
//
// A propeller clock.

void setup()
{
  // set up an interrupt handler on pin 2 to nitice fan pulses
  attachInterrupt( 0, fanPulseHandler, RISING );
  digitalWrite( 2, HIGH );
  
  // set up output pins (4 to 13) for the led array
  for( int a = 4; a < 14; a++ )
    pinMode( a, OUTPUT );

  // serial comms
  Serial.begin( 9600 );
}

// when non-zero, the time (in microseconds) of a new fan pulse that has just
// occurred, which means that segment drawing needs to be restarted
static unsigned long new_pulse_at = 0;

// interrupt handler to count the number of fan pulses
void fanPulseHandler()
{
  // ignore every other pulse
  static bool ignore = true;
  ignore = !ignore;
  if( !ignore )
  {
    // set a new pulse time
    new_pulse_at = micros();
  }
}

// wait until it is time to draw the next segment or a new pulse has occurred
void endOfSegmentDelay()
{
  while( micros() < next_segment_at && !new_pulse_at );
}

void loop()
{
  static int led = 4;

  unsigned long loop_start_time = micros();

  // wait till it's time to draw the next segment
  
}