2018-11-25 22:19:25 [显示全部楼层]
5462浏览
查看: 5462|回复: 2

[进阶] arduino颜色识别

[复制链接]
本帖最后由 gada888 于 2018-11-25 22:22 编辑

做一个简单的颜色识别,不用那么多的连线,对着arduno直插,当颜色模块对着一个物体的时候,串口就会读出相应的颜色用到的硬件只有TCS3200.和Arduino UNO。

arduino颜色识别图1
arduino颜色识别图2
TCS3200的电源输入电压是2.5v-5.5V
S0和S1是选频率的。两个都选HIGH
arduino颜色识别图3
连线是
• 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]


gada888  版主
 楼主|

发表于 2018-11-25 22:24:01

因出差,不方便放视频。
回复

使用道具 举报

hnyzcj  版主

发表于 2018-11-26 06:54:29

:lol
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

为本项目制作心愿单
购买心愿单
心愿单 编辑
[[wsData.name]]

硬件清单

  • [[d.name]]
btnicon
我也要做!
点击进入购买页面
上海智位机器人股份有限公司 沪ICP备09038501号-4 备案 沪公网安备31011502402448

© 2013-2024 Comsenz Inc. Powered by Discuz! X3.4 Licensed

mail