arduino用串口控制LGB
2015-06-07 13:38
531 查看
int redPin = 11; int greenPin = 10; int bluePin = 9; char rgb[18]; int ra[3]; int p=0; void setup() { Serial.begin(9600); pinMode(redPin, OUTPUT); pinMode(greenPin, OUTPUT); pinMode(bluePin, OUTPUT); } void loop() { if (Serial.available()>0) { delay(100); int i=0; int mao=Serial.available(); if (mao>15) mao=15; while (mao!=0) { rgb[i]=Serial.read(); i++; mao--; } rgblight(rgb); } } void rgblight(char* dota2) { Serial.print("This is:"); Serial.println(dota2); char* lol; lol=strtok(dota2," "); while (lol!=NULL) { Serial.println(atoi(lol)); lol=strtok(NULL," "); ra[p]=atoi(lol); p++; } RGB(ra[0],ra[1],ra[2]); ra[0]=0; ra[1]=0; ra[2]=0; for (int i=0;i<=17;i++){ rgb[i]='\0'; } } void RGB(int red, int green, int blue) { analogWrite(redPin, red); analogWrite(greenPin, green); analogWrite(bluePin, blue); }
相关文章推荐
- iOS UILocalizedIndexedCollation
- JUNIT(suite组合测试)
- NYOJ1100WAJUEJI which home strong!(bfs+优先队列)
- grunt 构建工具(build tool)初体验
- [镜像制作]VMWare搭建Openstack——guestfish命令修改虚拟机镜像
- UISprite扩展强化,减少游戏包大小功能及功能扩展【NGUI】
- UITextView默认文字提示
- 【leetcode】Distinct Subsequences
- iOS 蓝牙使用小结 bluetooth
- 【转】arm交叉编译器gnueabi、none-eabi、arm-eabi、gnueabihf、gnueabi区别
- UE4官方Third Person框架初学者见解
- 每日一得-org.hibernate.hql.ast.QuerySyntaxException: Path expected for join!错误解决办法
- Ant入门基础
- iOSProgramming: The Big Nerd Ranch Guide (4th Edition) 阅读笔记-关于 View 的 Redrawing 和 Run Loop
- iOS开发零基础教程之UILabel的新初始化方法
- NGUI -- UICamera(监听输入事件,鼠标,键盘等)
- valueForKeyPath用途
- 重用系统自带UITableViewCell
- String、StringBuilder与StringBuffer的区别
- requireJS入门