Code belonging to my TCS230 post

You need to read my other post for this to make sense!,134058.0.html

#include <TimerOne.h>

#define  SAMPLE  5000 // uSec for sample period  - you need to experiment with this!

#define OE     7
#define S0     6
#define S1     5
#define S2     4
#define S3     3
#define OUT    2 // MUST be on this pin to allow the external HW interrupt

volatile long    g_count;    // count the frequecy
volatile long    g_array[3];     // store the RGB value
volatile int color=0;
// Init TSC230 and setting Frequency. S0 & S1 parameterised for eas of play...
// default to LH i.e. 2% max freq
void Init(int bS0=LOW,int bS1=HIGH)
  pinMode(WB_LED, OUTPUT);
  pinMode(OE, OUTPUT);
  pinMode(S0, OUTPUT);
  pinMode(S1, OUTPUT);
  pinMode(S2, OUTPUT);
  pinMode(S3, OUTPUT);

  pinMode(OUT, INPUT);
  digitalWrite(S0, bS0);  // OUTPUT FREQUENCY SCALING
  digitalWrite(S1, bS1); 

  digitalWrite(OE, HIGH); // silent
// Select the filter color 
void setColor(int Level01, int Level02)
  digitalWrite(S2, Level01); 
  digitalWrite(S3, Level02); 
// ISRs
void freqCount() // ticks once per external INT (on pin 2)
  g_count++ ;

void getFreq(){
  noInterrupts(); // see notes
  digitalWrite(OE,HIGH); // stops Sq Wav...guarantees g_count won't change


    case 0:
     setColor(HIGH,HIGH); // GREEN
    case 1:
      setColor(LOW,HIGH); // BLUE
    case 2:
      setColor(LOW,LOW); // RED


  digitalWrite(OE,LOW); // carry on sampling
  interrupts(); // see notes
void setup()
  Contrary to the following comment from  the TimerOne library initialise():
  "// set mode as phase and frequency correct pwm, stop the timer"
  The timer actually starts ticking as soon as the call to initialise is complete.
  We don't want this (see above) so we disable INTS
  noInterrupts(); // prevent premature (any!) ticking
  Serial.println("Timer Initialised");
  Timer1.stop();    // keep Timer1 internal state consistent
  Serial.println("Timer Ready");
  attachInterrupt(0, freqCount, RISING);  
  Serial.println("Counter attached");
  Timer1.restart(); // * like now for example
  interrupts(); // now things will only start ticking when *I* tell them to (which is more like it!)

void loop()
   delay(10 * (SAMPLE / 1000));
   for(int i=0; i<3; i++){ 
// noInterrupts(); // see notes
// interrupts(); // see notes

A novel form of cross-posting - post it in the right thread only please