Arduino Uno带有色彩传感器TCS3200 RGB

时间:2017-04-12 10:49:43

标签: colors arduino rgb

我试图使用Arduino Uno和传感器TCS3200制作一个简单的程序。我想捕获扫描颜色的RGB值,但输出似乎不是RGB代码,因为值超过255并且它们与真实颜色不匹配。我认为返回的值是颜色的频率。

这是我的代码:

#define S0 4
#define S1 5
#define S2 6
#define S3 7
#define sensorOut 8
int frequency = 0;
void setup() {
  pinMode(S0, OUTPUT);
  pinMode(S1, OUTPUT);
  pinMode(S2, OUTPUT);
  pinMode(S3, OUTPUT);
  pinMode(sensorOut, INPUT);

  // Setting frequency-scaling to 20%
  digitalWrite(S0,HIGH);
  digitalWrite(S1,LOW);

  Serial.begin(9600);
}
void loop() {
  // Setting red filtered photodiodes to be read
  digitalWrite(S2,LOW);
  digitalWrite(S3,LOW);
  // Reading the output frequency
  frequency = pulseIn(sensorOut, LOW);
  //Remaping the value of the frequency to the RGB Model of 0 to 255
  frequency = map(frequency, 25,72,255,0);
  // Printing the value on the serial monitor
  Serial.print("R= ");//printing name
  Serial.print(frequency);//printing RED color frequency
  Serial.print("  ");
  delay(100);
  // Setting Green filtered photodiodes to be read
  digitalWrite(S2,HIGH);
  digitalWrite(S3,HIGH);
  // Reading the output frequency
  frequency = pulseIn(sensorOut, LOW);
  //Remaping the value of the frequency to the RGB Model of 0 to 255
  frequency = map(frequency, 30,90,255,0);
  // Printing the value on the serial monitor
  Serial.print("G= ");//printing name
  Serial.print(frequency);//printing RED color frequency
  Serial.print("  ");
  delay(100);
  // Setting Blue filtered photodiodes to be read
  digitalWrite(S2,LOW);
  digitalWrite(S3,HIGH);
  // Reading the output frequency
  frequency = pulseIn(sensorOut, LOW);
  //Remaping the value of the frequency to the RGB Model of 0 to 255
  frequency = map(frequency, 25,70,255,0);
  // Printing the value on the serial monitor
  Serial.print("B= ");//printing name
  Serial.print(frequency);//printing RED color frequency
  Serial.println("  ");
  delay(100);
}

有没有办法将频率值转换为精确的RGB颜色?

编辑:这是扫描灰色材料:

R= 174  G= 200  B= 340  
R= 174  G= 200  B= 317  
R= 174  G= 200  B= 323  
R= 174  G= 200  B= 323  
R= 174  G= 200  B= 323  
R= 174  G= 200  B= 323  
R= 180  G= 204  B= 323  
R= 185  G= 209  B= 323  
R= 180  G= 209  B= 323  
R= 185  G= 209  B= 323  
R= 185  G= 209  B= 323  
R= 218  G= 209  B= 323  
R= 185  G= 209  B= 328  

0 个答案:

没有答案