6114浏览
查看: 6114|回复: 0

[项目] 交作业,色彩模块TCS34725的测试

[复制链接]
大家好,非常感谢DFRobot寄来的测试颜色模块。拿到就迫不及待的测试了下。感觉灵敏度不错,应该有很多其他用途,留待以后研究了。这次只是测试了语音播报与颜色功能,程序开发主要参考了Adafruit官方库。
配件清单:
1.Arduino UNO
2。DFPRobot TCS34725
3.DFPlayer mini
4.8欧喇叭

交作业,色彩模块TCS34725的测试图1
[mw_shl_code=applescript,true]/*
A color sensor reader code created by Shanno in 2017,this code is under GNU protection,kidding,its in public site,you are free to use or modify without prior notice.if
you find it useful,please buy me a cup of tea if by chance we will meet in the future.
*/
#include <SoftwareSerial.h>
#include <DFPlayer_Mini_Mp3.h>
#include "Adafruit_TCS34725.h"

Adafruit_TCS34725 tcs = Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_50MS, TCS34725_GAIN_1X);
void setup() {
Serial.begin(9600);
  mp3_set_serial (Serial);  //set Serial for DFPlayer-mini mp3 module
  mp3_set_volume (25);
  delay (400);

if (tcs.begin()) {+-
Serial.println("TCS34725 Found");
} else {
Serial.println("TCS34725 not found!");
while (1);
}
delay(1000);
}
void loop() {

uint16_t transparant, red, green, blue;
float average, r, g, b;
tcs.getRawData(&red, &green, &blue, &transparant);

average = (red+green+blue)/3;
r = red/average;
g = green/average;
b = blue/average;
Serial.print("\tClear:");
Serial.print(transparant);
Serial.print("\tRED:");
Serial.print(r);
Serial.print("\tGREEN:");
Serial.print(g);
Serial.print("\tBLUE:");
Serial.print(b);

if ((r > 1.4) && (g < 0.9) && (b < 0.9)) { //Red detected
Serial.print("\tRED");
mp3_single_play (1);
  delay (1000);
}
else if ((r < 0.95) && (g > 1.4) && (b < 0.9)) { //Green detected
Serial.print("\tGreen");
mp3_single_play (2);
  delay (1000);
}
else if ((r < 0.8) && (g < 1.2) && (b > 1.2)) { //Blue detected
Serial.print("\tBLUE");
mp3_single_play (3);
  delay (1000);
}
else if ((r > 1.15) && (g > 1.15) && (b < 0.7)) { //Yelow detected
Serial.print("\tYELLOW");
mp3_single_play (4);
delay (1000);
}
else if ((r > 1.4) && (g < 1.0) && (b < 0.7)) { //Orange Detected
Serial.print("\tORANGE");
mp3_single_play (5);
  delay (1000);
}
else {
Serial.print("\tNoColor");
  mp3_single_play (6);
  delay (1000);
}
Serial.println("");
delay(1000);
}

[/mw_shl_code]
视频地址:
https://v.youku.com/v_show/id_XM ... rsttime=150#paction

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

本版积分规则

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

硬件清单

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

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

mail