ArduinoGeneral

Issues with slowing down TCS 3200 color sensor readings

userHead thorobred 2014-02-09 07:34:28 2730 Views4 Replies
Hello I'm am new to this forum and I have a question regarding the TCS 3200 color sensor that I am testing. The sensor works fine with the example code I used to read the color but it reads it at a very fast rate. I have been trying to slow it down with putting delays at certain parts of the code but it does not help. I was hoping that someone that is more experienced can help me with this issue? Code pasted below.[code]int s0=3,s1=4,s2=5,s3=6;
int out=2;
int flag=0;
byte counter=0;
byte countR=0,countG=0,countB=0;
void setup()
{
Serial.begin(9600);
pinMode(s0,OUTPUT);
pinMode(s1,OUTPUT);
pinMode(s2,OUTPUT);
pinMode(s3,OUTPUT);
}
void TCS()
{
flag=0;
digitalWrite(s1,HIGH);
digitalWrite(s0,HIGH);
digitalWrite(s2,LOW);
digitalWrite(s3,LOW);
attachInterrupt(0, ISR_INTO, LOW);
timer0_init();
}
void ISR_INTO()
{
counter++;
}
void timer0_init(void)
{
  TCCR2A=0x00;
  TCCR2B=0x07;  //the clock frequency source 1024 points
  TCNT2= 100;    //10 ms overflow again
  TIMSK2 = 0x01; //allow interrupt
}
int i=0;
ISR(TIMER2_OVF_vect)//the timer 2, 10ms interrupt overflow again. Internal overflow interrupt executive function
{
    TCNT2=100;
    flag++;
if(flag==1)
  {
    countR=counter;
    Serial.print("red=");
    Serial.println(countR,DEC);
    digitalWrite(s2,HIGH);
    digitalWrite(s3,HIGH);
   
  }
  else if(flag==2)
  {
    countG=counter;
    Serial.print("green=");
    Serial.println(countG,DEC);
    digitalWrite(s2,LOW);
    digitalWrite(s3,HIGH);
   
  }
  else if(flag==3)
    {
    countB=counter;
    Serial.print("blue=");
    Serial.println(countB,DEC);
    Serial.println("\n");
    digitalWrite(s2,LOW);
    digitalWrite(s3,LOW);
   
   
    }
    else if(flag==4)
    {
    flag=0;
   
    }
      counter=0;
     
}
void loop()
{
  TCS();
 
while(1);
}[/code]
2014-02-11 14:28:53

What serial prints are you referring to? The one that displays each color?
[/quote]

That's right. But I am guessing you would want to be faster rather than slow.
Maybe you should clean up a little the results. I have not used this sensor yet. But It might be a good idea to do some sampling, store it on some array, average it and then print it. To avoid ambient light noise readings. that could make it hard to read.
userHeadPic Jose
2014-02-09 23:17:10 [quote="Jose"]
Hello Thorobred and welcome!

Perhaps you can put the Serial prints outside of that function and add delay at the time you want to serial print it.
Why would you like to slow it down ? I thought the faster it gets the better!
[/quote]

What serial prints are you referring to? The one that displays each color?
userHeadPic thorobred
2014-02-09 23:13:59 The reason I want to slow it down is to see if its reading the object i am putting over the sensor correctly. userHeadPic thorobred
2014-02-09 13:25:43 Hello Thorobred and welcome!

Perhaps you can put the Serial prints outside of that function and add delay at the time you want to serial print it.
Why would you like to slow it down ? I thought the faster it gets the better!
userHeadPic Jose