Use LCD Keyboard Shieid to show color sensor's data which received [1.2]
来源:互联网 发布:joo yeon seo韩国 编辑:程序博客网 时间:2024/05/18 11:45
The code can be use ,but there's something wrong with it.
it only shows a few sets of data,and then it stops.
#include <LiquidCrystal.h>LiquidCrystal lcd(8,9,4,5,6,7);int s0=6,s1=5,s2=4,s3=3;//int s0=3,s1=4,s2=5,s3=6;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); lcd.setCursor(0,0); lcd.print("R="); lcd.setCursor(2,0); lcd.print(" "); lcd.setCursor(2,0); lcd.print(countR,DEC); digitalWrite(s2,HIGH); digitalWrite(s3,HIGH); } else if(flag==2) { countG=counter; colorshow[1]=counter; Serial.print("green="); Serial.println(countG,DEC); lcd.setCursor(5,0); lcd.print("G="); lcd.setCursor(7,0); lcd.print(" "); lcd.setCursor(7,0); lcd.print(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"); lcd.setCursor(10,0); lcd.print("B="); lcd.setCursor(12,0); lcd.print(" "); lcd.setCursor(12,0); lcd.print(countB,DEC); digitalWrite(s2,LOW); digitalWrite(s3,LOW); } else if(flag==4) { flag=0; lcd.setCursor(0,1); lcd.print(" "); lcd.setCursor(0,2); lcd.print("Color:"); lcd.setCursor(7,2); if((colorshow[0]>220)&&(colorshow[1]>220)&&(colorshow[2]>220)) lcd.print("White"); else if((colorshow[0]<50)&&(colorshow[1]<50)&&(colorshow[2]<50)) lcd.print("Black"); else if((colorshow[1]>colorshow[0])&&(colorshow[1]>colorshow[2])) lcd.print("Green"); else if((colorshow[2]>colorshow[0])&&(colorshow[2]>colorshow[1])) lcd.print("Purple"); else if((colorshow[0]>colorshow[1])&&(colorshow[0]>colorshow[2])) lcd.print("Red"); //lcd.print(colorshow[1]); // a simple color decision 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
- 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]
- Use Django to show data
- TCS3200 Color Sensor's directions for use [1.8]
- How to use HttpWebRequest to post data to another page which is on another server
- Decide which type to use
- How to use ARM's data-abort exception (quote)
- How DirectShow Decides Which Filters to Use
- which to use: ext3, JFS, XFS, ReiserFS?
- Which type to use in Cpp
- writing .NET applications, which language to use?
- On data dictionary synchronization errors:show which table is error
- Use View.isInEditMode() in your custom views to skip code or show sample data when shown in the IDE
- Use View.isInEditMode() in your custom views to skip code or show sample data when shown in the IDE
- Use View.isInEditMode() in your custom views to skip code or show sample data when shown in the IDE
- How To use Data Referenece ...
- The simple test for LCD Keypad Shieid [1.6]
- Using Python to show the test data
- vsftpd+pam+mysql
- spring boot整合redis
- Nodejs+Vuejs实现无限分类关系
- SEO新手必学:充分了解搜索引擎盈利模式
- 51单片机的中断系统(六)
- Use LCD Keyboard Shieid to show color sensor's data which received [1.2]
- Python购物流程结合ATM接口实现
- linux centos7 下 mysql5.6安装
- transient关键字
- JZOJ5372. 【NOIP2017提高A组模拟9.17】猫 链表+贪心+堆优化
- 汉诺塔问题
- javascript原型链详细解析(二)
- shiro配置问题
- 关于通过curl函数请求微信接口的总结