BASIC4MCU | 질문게시판 | 답변 : 색상인식과 진동모터
페이지 정보
작성자 master 작성일2019-11-27 22:16 조회3,874회 댓글0건
https://www.basic4mcu.com/bbs/board.php?bo_table=gac&wr_id=10930
본문
//#include <Wire.h>#include "Adafruit_TCS34725.h"Adafruit_TCS34725 tcs=Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_50MS,TCS34725_GAIN_4X);//#define commonAnode true#define redpin 3#define greenpin 5#define bluepin 6//byte gammatable[256];//void setup(){Serial.begin(9600);if(!tcs.begin()){ Serial.println("No TCS34725 found..."); while(1); }//pinMode(redpin,OUTPUT); pinMode(greenpin,OUTPUT); pinMode(bluepin,OUTPUT);//for(int i=0; i<256; i++){float x=i/255.0;x=pow(x,2.5);x*=255;if(commonAnode){ gammatable[i]=255-x; }else { gammatable[i]=x; }}}//void loop(){float red,green,blue;tcs.setInterrupt(false); // turn on LEDdelay(60);tcs.getRGB(&red,&green,&blue);tcs.setInterrupt(true); // turn off LED//Serial.print("R: \t"); Serial.print(int(red));Serial.print("\tG: \t"); Serial.print(int(green));Serial.print("\tB: \t"); Serial.println(int(blue));//analogWrite(redpin,gammatable[(int)red]);analogWrite(greenpin,gammatable[(int)green]);analogWrite(bluepin,gammatable[(int)blue]);}
https://github.com/adafruit/Adafruit_TCS34725/blob/master/examples/colorview/colorview.ino
이 글의 예제 소스군요
Serial.print("R: \t"); Serial.print(int(red));
Serial.print("\tG: \t"); Serial.print(int(green));Serial.print("\tB: \t"); Serial.println(int(blue));노란색을 대었을 때 시리얼 모니터에 각 색상별 값이 얼마로 나오는지 체크하세요그 값으로 if()문을 작성해서 진동모터를 구동하면 됩니다.
댓글 0
조회수 3,874등록된 댓글이 없습니다.