ColorPAL顏色感測器  查看大圖

ColorPAL 顏色感測器

SSO0012

ColorPAL是一種小型的顏色和光感測器,透過它的RGB LED,亦可作為辨識色彩時的產生器。

更多資訊

NT$ 819 含稅

更多資訊

產品簡介:

ColorPAL是一種小型的顏色和光感測器,透過它的RGB LED,亦可作為辨識色彩時的產生器。當檢測顏色時,ColorPAL使用其LED照亮樣本;一種色彩元素組成的時候,會隨著產生一種譜光,轉換到電壓轉換器來測量反射回來的光。從樣本反射的光量,分成紅色(R),綠色(G)和藍色(B)三原色 來確定樣本的顏色。本ColorPAL工作於非瑩光的反射面,最好是接觸在它的LED光罩。 

 

產品規格:

  • 電源要求:5.0V
  • 通訊:Serial 1-Wire (asynchronous serial, open drain)串列單接口
  • 尺寸:44 × 23 × 17mm 

 

文件下載:

 

補充資料:

Arduino Code:


 
/* ColorPal Sensor Example for Arduino
  Author: Martin Heermance, with some assistance from Gordon McComb
  This program drives the Parallax ColorPAL color sensor and provides
  serial RGB data in a format compatible with the PC-hosted
  TCS230_ColorPAL_match.exe color matching program.
*/

#include <SoftwareSerial.h>

const int sio = 2;            // ColorPAL connected to pin 2
const int unused = 255;         // Non-existant pin # for SoftwareSerial
const int sioBaud = 4800;
const int waitDelay = 200;

// Received RGB values from ColorPAL
int red;
int grn;
int blu;

// Set up two software serials on the same pin.
SoftwareSerial serin(sio, unused);
SoftwareSerial serout(unused, sio);

void setup() {
  Serial.begin(9600);
  reset();                  // Send reset to ColorPal
  serout.begin(sioBaud);
  pinMode(sio, OUTPUT);
  serout.print("= (00 $ m) !"); // Loop print values, see ColorPAL documentation
  serout.end();              // Discontinue serial port for transmitting

  serin.begin(sioBaud);            // Set up serial port for receiving
  pinMode(sio, INPUT);
}

void loop() {
  readData();
}  

// Reset ColorPAL; see ColorPAL documentation for sequence
void reset() {
  delay(200);
  pinMode(sio, OUTPUT);
  digitalWrite(sio, LOW);
  pinMode(sio, INPUT);
  while (digitalRead(sio) != HIGH);
  pinMode(sio, OUTPUT);
  digitalWrite(sio, LOW);
  delay(80);
  pinMode(sio, INPUT);
  delay(waitDelay);
}

void readData() {
  char buffer[32];

  if (serin.available() > 0) {
    // Wait for a $ character, then read three 3 digit hex numbers
    buffer[0] = serin.read();
    if (buffer[0] == '$') {
      for(int i = 0; i < 9; i++) {
        while (serin.available() == 0);     // Wait for next input character
        buffer[i] = serin.read();
        if (buffer[i] == '$')               // Return early if $ character encountered
          return;
      }
      parseAndPrint(buffer);
      delay(10);
    }
  }
}

// Parse the hex data into integers
void parseAndPrint(char * data) {
  sscanf (data, "%3x%3x%3x", &red, &grn, &blu);
  char buffer[32];
  sprintf(buffer, "R%4.4d G%4.4d B%4.4d", red, grn, blu);
  Serial.println(buffer);
}