5462| 2
|
[进阶] arduino颜色识别 |
本帖最后由 gada888 于 2018-11-25 22:22 编辑 做一个简单的颜色识别,不用那么多的连线,对着arduno直插,当颜色模块对着一个物体的时候,串口就会读出相应的颜色用到的硬件只有TCS3200.和Arduino UNO。 TCS3200的电源输入电压是2.5v-5.5V S0和S1是选频率的。两个都选HIGH 连线是 • S0 ------ D3 Arduino • S1 ------ D4 Arduino • S2 ------ D5 Arduino • S3 ------ D6 Arduino • OUT ---- D7 Arduino Vdd----VCC arduino GND---GND arduino [mw_shl_code=applescript,true]// gada888 int pulsePin = 7; int prescale0Pin = 3; int prescale1Pin = 4; int colorSelect0pin = 5; int colorSelect1pin = 6; void setup() { pinMode(prescale0Pin, OUTPUT); pinMode(prescale1Pin, OUTPUT); // set maximum prescale digitalWrite(prescale0Pin, HIGH); digitalWrite(prescale1Pin, HIGH); pinMode(colorSelect0pin, OUTPUT); pinMode(colorSelect1pin, OUTPUT); pinMode(pulsePin, INPUT); Serial.begin(9600); Serial.println("Color Reader"); } void loop() { long red = readRed(); long green = readGreen(); long blue = readBlue(); if (red < green && red < blue) { Serial.println("RED"); } if (green < red && green < blue) { Serial.println("GREEN"); } if (blue < green && blue < red) { Serial.println("BLUE"); } delay(500); } long readRed() { return (readColor(LOW, LOW)); } long readGreen() { return (readColor(HIGH, HIGH)); } long readBlue() { return (readColor(LOW, HIGH)); } long readWhite() { return (readColor(HIGH, LOW)); } long readColor(int bit0, int bit1) { digitalWrite(colorSelect0pin, bit0); digitalWrite(colorSelect1pin, bit1); long start = millis(); for (int i=0; i< 1000; i++) { pulseIn(pulsePin, HIGH); } return (millis() - start); } void printRGB() { Serial.print(readRed()); Serial.print("\t"); Serial.print(readGreen()); Serial.print("\t"); Serial.print(readBlue()); Serial.print("\t"); Serial.println(readWhite()); } [/mw_shl_code] |
© 2013-2024 Comsenz Inc. Powered by Discuz! X3.4 Licensed