TCS230 RGB color sensor

hi guys im new to arduino and im not that good at electronics,
for my colg project, I am suppose to make a robot (a modified rc car) that can detect the color and move based on it,
I recently bought a TCS230 RGB color sensor and I found a working code for it from the web(don't know from where I got it though :confused: )

ok so I tried running the code and was able to get some reliable readings , but when I try to give a command to a servo to turn to a specific angle based on the color value obtained nothing works the servo acts on its own, it keeps turning in one direction and gets stuck there, I tried using the same code but instead of doing something with servo I send the required servo angle to my serial monitor and im able to get it

lets say I want the motor to turn 40degree when I get a reading of R 800, G 700, B 500
ie when i have a total reading of <2000 i want the servo to turn to 0
and when I have a total of 4000+ I want my servo to turn to 180
everything works except servo.
I read somewhere that its coz of the timer1 interrupt , since it is used for the color sensor, I don't know how to get the readings from the TCS230 without interrupts, im using a code that I found on the net, and when I tried using normal ATD to get the readings im getting unreliable ,highly fluctuating readings, can some one tell me how I can use the servo with the TCS230? or a way to get readings from TCS230 without timer1 interrupts, im running low on time , any help at the earliest would be greatly appreciated ..

jim

#include <TimerOne.h>

#define S0     6
#define S1     5
#define S2     4
#define S3     3
#define OUT    2

int   g_count = 0;    // count the frequecy
int   g_array[3];     // store the RGB value
int   g_flag = 0;     // filter of RGB queue
float g_SF[3];        // save the RGB Scale factor
 
 
// Init TSC230 and setting Frequency.
void TSC_Init()
{
  pinMode(S0, OUTPUT);
  pinMode(S1, OUTPUT);
  pinMode(S2, OUTPUT);
  pinMode(S3, OUTPUT);
  pinMode(OUT, INPUT);
 
  digitalWrite(S0, LOW);  // OUTPUT FREQUENCY SCALING 2%
  digitalWrite(S1, HIGH); 
}
 
// Select the filter color 
void TSC_FilterColor(int Level01, int Level02)
{
  if(Level01 != 0)
    Level01 = HIGH;
 
  if(Level02 != 0)
    Level02 = HIGH;
 
  digitalWrite(S2, Level01); 
  digitalWrite(S3, Level02); 
}
 
void TSC_Count()
{
  g_count ++ ;
}
 
void TSC_Callback()
{
  switch(g_flag)
  {
    case 0: 
         Serial.println("->WB Start");
         TSC_WB(LOW, LOW);              //Filter without Red
         break;
    case 1:
         Serial.print("->Frequency R=");
         Serial.println(g_count);
         g_array[0] = g_count;
         TSC_WB(HIGH, HIGH);            //Filter without Green
         break;
    case 2:
         Serial.print("->Frequency G=");
         Serial.println(g_count);
         g_array[1] = g_count;
         TSC_WB(LOW, HIGH);             //Filter without Blue
         break;
 
    case 3:
         Serial.print("->Frequency B=");
         Serial.println(g_count);
         Serial.println("->WB End");
         g_array[2] = g_count;
         TSC_WB(HIGH, LOW);             //Clear(no filter)   
         break;
   default:
         g_count = 0;
         break;
  }
}
 
void TSC_WB(int Level0, int Level1)      //White Balance
{
  g_count = 0;
  g_flag ++;
  TSC_FilterColor(Level0, Level1);
  Timer1.setPeriod(1000000);             // set 1s period
}
 
void setup()
{
  TSC_Init();
  Serial.begin(9600);
  Timer1.initialize();             // defaulte is 1s
  Timer1.attachInterrupt(TSC_Callback);  
  attachInterrupt(0, TSC_Count, RISING);  
 
  delay(4000);
 
  for(int i=0; i<3; i++)
    Serial.println(g_array[i]);
 
  g_SF[0] = 255.0/ g_array[0];     //R Scale factor
  g_SF[1] = 255.0/ g_array[1] ;    //G Scale factor
  g_SF[2] = 255.0/ g_array[2] ;    //B Scale factor
 
  Serial.println(g_SF[0]);
  Serial.println(g_SF[1]);
  Serial.println(g_SF[2]);
 
}
 
void loop()
{
   g_flag = 0;
   for(int i=0; i<3; i++)
    Serial.println(int(g_array[i] * g_SF[i]));
   delay(4000);
 
}

[/SPOILER]

can some one tell me a way to use the sensor without interrups? guys pls replay :confused: