交作业,色彩模块TCS34725的测试
2017-11-271.5万
AI 快速预览详细
本文介绍了如何使用TCS34725色彩模块、Arduino UNO和DFPlayer mini实现颜色识别并语音播报。配件清单包括Arduino UNO、DFRobot TCS34725、DFPlayer mini和8欧喇叭。程序基于Adafruit官方库开发,通过特定参数配置实现高灵敏度的颜色识别。该项目适合初学者和STEM教育场景,能够锻炼学生的动手能力和逻辑思维。
|
大家好,非常感谢DFRobot寄来的测试颜色模块。拿到就迫不及待的测试了下。感觉灵敏度不错,应该有很多其他用途,留待以后研究了。这次只是测试了语音播报与颜色功能,程序开发主要参考了Adafruit官方库。 配件清单: 1.Arduino UNO 2。DFPRobot TCS34725 3.DFPlayer mini 4.8欧喇叭 ![]() [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 |




