TCS3200 Color Sensor's directions for use [1.8]
来源:互联网 发布:countdown软件 怎么用 编辑:程序博客网 时间:2024/06/02 03:12
I connect color sensor with Arduino,to complete the function that can get object's color.
This code can make test won't stop.
GND & LED – GND , OE – GND, VCC – VCC,
S0 – D6, S1 – D5, S2 – D4, S3 – D3, OUT – D2
#include <LiquidCrystal.h>LiquidCrystal lcd(8,9,4,5,6,7);//int s0=3,s1=4,s2=5,s3=6;int s0=6,s1=5,s2=4,s3=3;int out=2;int flag=0;byte counter=0;int colorshow[3];double timebegin;byte countR=0,countG=0,countB=0;void setup() { Serial.begin(9600); pinMode(10,OUTPUT); lcd.begin(16,2); digitalWrite(10,HIGH); pinMode(s0,OUTPUT); pinMode(s1,OUTPUT); pinMode(s2,OUTPUT); pinMode(s3,OUTPUT); }void TCS() { flag=0; digitalWrite(s1,HIGH); digitalWrite(s0,HIGH); digitalWrite(s2,LOW); digitalWrite(s3,LOW); attachInterrupt(0, ISR_INTO, LOW); timer0_init(); }void ISR_INTO() { counter++; } void timer0_init(void) { TCCR2A=0x00; TCCR2B=0x07; //the clock frequency source 1024 points TCNT2= 100; //10 ms overflow again TIMSK2 = 0x01; //allow interrupt } int i=0; ISR(TIMER2_OVF_vect)//the timer 2, 10ms interrupt overflow again. Internal overflow interrupt executive function{ TCNT2=100; flag++; if(flag==1) { countR=counter; colorshow[0]=counter; Serial.print("red="); Serial.println(countR,DEC); digitalWrite(s2,HIGH); digitalWrite(s3,HIGH); } else if(flag==2) { countG=counter; colorshow[1]=counter; Serial.print("green="); Serial.println(countG,DEC); digitalWrite(s2,LOW); digitalWrite(s3,HIGH); } else if(flag==3) { countB=counter; colorshow[2]=counter; Serial.print("blue="); Serial.println(countB,DEC); Serial.println("\n"); digitalWrite(s2,LOW); digitalWrite(s3,LOW); } else if(flag==4) { flag=0; /*if((colorshow[0]>220)&&(colorshow[1]>220)&&(colorshow[2]>220)) Serial.println("White"); else if((colorshow[0]<50)&&(colorshow[1]<50)&&(colorshow[2]<50)) Serial.println("Black"); else if((colorshow[1]>colorshow[0])&&(colorshow[1]>colorshow[2])) Serial.println("Green"); else if((colorshow[2]>colorshow[0])&&(colorshow[2]>colorshow[1])) Serial.println("Purple"); else if((colorshow[0]>colorshow[1])&&(colorshow[0]>colorshow[2])) Serial.println("Red"); Serial.println("\n"); */ } counter=0; //delay(10);}void loop() { TCS(); //delay(1000); while(1); }
阅读全文
1 0
- TCS3200 Color Sensor's directions for use [1.8]
- Use LCD Keyboard Shieid to show color sensor's data which received [1.2]
- Use LCD Keyboard Shieid to show color sensor's data which received [2.1]
- Mobile, Wireless and Sensor Networks : Technology, Applications and Future Directions
- 英语练习104 Asking for directions
- Going Shopping: Asking for directions(1) 问路1
- Directions for having MATLAB startup in your last working directory
- Tactile Sensor and Force Torque Sensor: What's the Difference?
- compensate capacitance 's use
- Google's Application Security Tools For All To Learn With & Use! http://
- TCS3200颜色传感器测试实验:
- The robot API &&How to add and use sensor.
- Use Retation Sensor to control the brightness of LED lights
- channel directions
- Use xDoclet For Hibernate
- Use for-each liberally
- git command for use
- The best color for programmer
- 基于 WebBroker 的 CMS 源代码已经发布
- Java -- 集合List
- 浏览器获取cookie的两种方式
- 三种方法模拟实现strlen函数
- nginx配置跨域
- TCS3200 Color Sensor's directions for use [1.8]
- TensorFlow图像数据处理
- JavaScript学习摘录(一)
- 基于Retrofit + RxJava的http请求的封装
- String,StringBuffer和StringBuilder
- 解决WordPress安装插件输入FTP账户信息
- (某网络公司笔试题)判断一个点是否在三角形内
- orange_17.09.18学习unity-菜单栏MenuItem
- TypeError: slice indices must be integers or None or have an index method