หมวดหมู่ | Sensor/Encoder |
ราคา | 380.00 บาท |
สภาพ | สินค้าใหม่ |
ลงสินค้า | 20 มี.ค. 2558 |
อัพเดทล่าสุด | 22 พ.ค. 2566 |
เซ็นเซอร์สี V1.0
วิธีการเซตค่าสีจากตัวอย่างโค้ด
- หากระดาษสี CMY หรือปริ้นกระดาษโทนแม่สี CMY เพื่อเตรียมพร้อมสำหรับการคาริเบต
- กดรีเซตไมโครคอนโทรลเลอร์ จะสังเกตเห็นว่า LED มีไฟสีขาวติดสว่าง
- ทำการกด SW บนบอร์ดเซ็นเซอร์สี1ครั้ง จะสังเกตเห็นว่า LED เปลี่ยนเป็นสีฟ้า(C) ให้นำบอร์ดเซ็นเซอร์สีไปวางบนกระดาษสีฟ้า
- จากนั้นทำการกด SW อีกครั้ง ไมโครคอนโทรลเลอร์จะทำการเก็บค่าโทนสีฟ้า หลังจากเก็บค่าสีฟ้าเสร็จแล้วสังเกต LED จะเปลี่ยนเป็นสีม่วง(M) ให้นำบอร์ดเซ็นเซอร์สีไปวางบนกระดาษสีม่วง
- จากนั้นทำการกด SW อีกครั้ง ไมโครคอนโทรลเลอร์จะทำการเก็บค่าโทนสีม่วง หลังจากเก็บค่าสีม่วงเสร็จแล้วสังเกต LED จะเปลี่ยนเป็นสีเหลือง(Y) ให้นำบอร์ดเซ็นเซอร์สีไปวางบนกระดาษสีเหลือง
- จากนั้นทำการกด SW อีกครั้ง ไมโครคอนโทรลเลอร์จะทำการเก็บค่าโทนสีเหลือง หลังจากเก็บค่าสีเหลืองเสร็จแล้ว เป็นอันเสร็จสิ้นการคาริเบต
- นำเซ็นเซอร์ไปวัดค่าสีต่างๆได้เลย โดยค่าสีจะแสดงออกทาง LED RGB ที่อยู่บนบอร์ดเซ็นเซอร์ และโชว์ค่า RGB ขึ้นบนจอมอนิเตอร์ถ้าเราเชื่อมต่อผ่าน Serial Port
แต่ถ้าหากต้องการคาริเบตค่าสีใหม่ให้ทำการกด SW อีกครั้งกดค้างไว้ประมาณ 1 วินาที ระบบก็จะเข้าสู่โหมดทำการคาริเบตสีใหม่
Example Code
boolean runColor = false;
// set pin numbers:
const int buttonPin = 2; // the number of the pushbutton pin
int pwmrgb[] = {3, 5, 6};
//sets the bias for the illuminated RGB LED: higher number = less intense (max 255)
int rgbbias[] = {20, 30, 0};
int rgbds[] = {0, 0, 0};
int Rc=0, Gc=0, Bc=0;
int Rm=0, Gm=0, Bm=0;
int Ry=0, Gy=0, By=0;
int rgb[] = {0, 0, 0};
int maxwhite[] = {1023, 1023, 1023};
int minblack[] = {0, 0, 0};
int sensorValue = 0;
int red;
int green;
int blue;
int speed = 60;
// Variables will change:
int a = 0;
int ledState = HIGH; // the current state of the output pin
int buttonState; // the current reading from the input pin
int lastButtonState = LOW; // the previous reading from the input pin
long lastDebounceTime = 0; // the last time the output pin was toggled
long debounceDelay = 50; // the debounce time; increase if the output flickers
void setup() {
pinMode(buttonPin, INPUT);
pinMode(3, OUTPUT); //Ro
pinMode(5, OUTPUT); //Go
pinMode(6, OUTPUT); //Bo
pinMode(9, OUTPUT); //sensor red cathode Ri
pinMode(10, OUTPUT); //sensor green cathode Gi
pinMode(11, OUTPUT); //sensor blue cathode Bi
Serial.begin(9600);
for(int j=0; j<3; j++) {
digitalWrite(j + 9, LOW);
delay(speed);
rgb[j] += analogRead(A1);
delay(speed);
digitalWrite(j + 9, HIGH);
delay(speed);
}
digitalWrite(3, HIGH);
digitalWrite(5, HIGH);
digitalWrite(6, HIGH);
}
void loop() {
// read the state of the switch into a local variable:
int reading = digitalRead(buttonPin);
if (reading != lastButtonState) {
// reset the debouncing timer
lastDebounceTime = millis();
}
if ((millis() - lastDebounceTime) > debounceDelay) {
if (reading != buttonState) {
buttonState = reading;
if (buttonState == LOW) {
a += 1;
}
}
}
lastButtonState = reading;
if(a == 1) {
runColor = false;
analogWrite(pwmrgb[0], 0);
analogWrite(pwmrgb[1], 200);
analogWrite(pwmrgb[2], 255);
}
else if(a == 2) {
calibateC();
a += 1;
analogWrite(pwmrgb[0], 255);
analogWrite(pwmrgb[1], 0);
analogWrite(pwmrgb[2], 200);
}
else if(a == 4) {
calibateM();
a += 1;
analogWrite(pwmrgb[0], 255);
analogWrite(pwmrgb[1], 160);
analogWrite(pwmrgb[2], 0);
}
else if(a == 6) {
calibateY();
a += 1;
maxwhite[0] = (Rm+Ry)/2;
maxwhite[1] = (Gc+Gy)/2;
maxwhite[2] = (Bc+Bm)/2;
minblack[0] = Rc;
minblack[1] = Gm;
minblack[2] = By;
Serial.print("maxR "); Serial.print(maxwhite[0]);
Serial.print("\tmaxG "); Serial.print(maxwhite[1]);
Serial.print("\tmaxB "); Serial.println(maxwhite[2]);
Serial.print("minR "); Serial.print(minblack[0]);
Serial.print("\tminG "); Serial.print(minblack[1]);
Serial.print("\tminB "); Serial.println(minblack[2]);
runColor = true;
a = 0;
}
if(runColor == true) {
for(int i = 0; i < 3; i++){
// delay(speed);
digitalWrite(i + 9, LOW);
delay(speed);
sensorValue = analogRead(A1);
delay(speed);
digitalWrite(i + 9, HIGH);
rgbds[i] = constrain(sensorValue, minblack[i], maxwhite[i]);
rgbds[i] = map(rgbds[i], minblack[i], maxwhite[i], 0, 255);
rgbds[i] = 255-((255 + rgbbias[i]) - rgbds[i]);
rgbds[i] = constrain(rgbds[i], 0, 255);
// digitalWrite(i + 9, HIGH);
}
for(int i = 0; i < 3; i++){
analogWrite(pwmrgb[i], rgbds[i]);
if(i == 0){
red = rgbds[0];
Serial.print("Red = ");
Serial.print(red);
Serial.print(" , ");
}
if(i == 1){
green = rgbds[1];
Serial.print("Green = ");
Serial.print(green);
Serial.print(" , ");
}
if(i == 2){
blue = rgbds[2];
Serial.print("Blue = ");
Serial.print(blue);
Serial.println();
}
}
delay(5);
}
else if(a == 8) {
runColor == false;
a=0;
}
}
void calibateC() {
Rc=0; Gc=0; Bc=0;
rgb[0] = 0; rgb[1] = 0; rgb[2] = 0;
for(int i=0; i<3; i++) {
for(int j=0; j<3; j++) {
digitalWrite(j + 9, LOW);
delay(speed);
rgb[j] += analogRead(A1);
delay(speed);
digitalWrite(j + 9, HIGH);
// delay(speed);
}
}
Rc = rgb[0]/3;
Gc = rgb[1]/3;
Bc = rgb[2]/3;
Serial.print("Rc "); Serial.print(Rc);
Serial.print("\tGc "); Serial.print(Gc);
Serial.print("\tBc "); Serial.println(Bc);
}
void calibateM() {
Rm=0; Gm=0; Bm=0;
rgb[0] = 0; rgb[1] = 0; rgb[2] = 0;
for(int i=0; i<3; i++) {
for(int j=0; j<3; j++) {
digitalWrite(j + 9, LOW);
delay(speed);
rgb[j] += analogRead(A1);
delay(speed);
digitalWrite(j + 9, HIGH);
// delay(speed);
}
}
Rm = rgb[0]/3;
Gm = rgb[1]/3;
Bm = rgb[2]/3;
Serial.print("Rm "); Serial.print(Rm);
Serial.print("\tGm "); Serial.print(Gm);
Serial.print("\tBm "); Serial.println(Bm);
}
void calibateY() {
Ry=0; Gy=0; By=0;
rgb[0] = 0; rgb[1] = 0; rgb[2] = 0;
for(int i=0; i<3; i++) {
for(int j=0; j<3; j++) {
digitalWrite(j + 9, LOW);
delay(speed);
rgb[j] += analogRead(A1);
delay(speed);
digitalWrite(j + 9, HIGH);
// delay(speed);
}
}
Ry = rgb[0]/3;
Gy = rgb[1]/3;
By = rgb[2]/3;
Serial.print("Ry "); Serial.print(Ry);
Serial.print("\tGy "); Serial.print(Gy);
Serial.print("\tBy "); Serial.println(By);
}
สอบถามสินค้าหรือต้องการใบเสนอราคาหรือใบกำกับภาษีโปรดติดต่อทางร้านก่อนสั่งซื้อครับผม
- ติดต่อผ่าน LINE ID : csanthanaboun
- เบอร์โทร 0909761799
หน้าที่เข้าชม | 332,811 ครั้ง |
ผู้ชมทั้งหมด | 120,848 ครั้ง |