2019-3-12 15:13:06 [显示全部楼层]
3232浏览
查看: 3232|回复: 3

[教程] App Inventor通过蓝牙控制Arduino RGB LED灯依次点亮

[复制链接]
使用蓝牙模块HC-05与App Inventor通信。早期的帖子因为要给MIT写博客,所以app的界面及编程环境用的是英文。(请忽略俺凌乱的接线)
2019-03-12 15.16.37.gif
截图201903101559366944.png
Arduino编程部分:
[mw_shl_code=applescript,true]void setup() {
// put your setup code here, to run once:
Serial.begin(9600);//SERIAL_8E2
Serial.setTimeout(3000);
pinMode(13, OUTPUT);
digitalWrite(13, HIGH);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
}

void loop() {
// put your main code here, to run repeatedly:
byte cmmd[20];
int insize;
while(1){
if((insize = Serial.available())> 0){
for(int i = 0; i < insize; i++){
cmmd = Serial.read();
}
}
switch(cmmd[0]){
case 97:
digitalWrite(5, LOW);
digitalWrite(6, LOW);
digitalWrite(7, LOW);
break;
case 98:
digitalWrite(5, LOW);
digitalWrite(6, LOW);
digitalWrite(7, HIGH);
break;
case 99:
digitalWrite(5, LOW);
digitalWrite(6, HIGH);
digitalWrite(7, LOW);
break;
case 100:
digitalWrite(5, LOW);
digitalWrite(6, HIGH);
digitalWrite(7, HIGH);
break;
case 101:
digitalWrite(5, HIGH);
digitalWrite(6, LOW);
digitalWrite(7, LOW);
break;
case 102:
digitalWrite(5, HIGH);
digitalWrite(6, LOW);
digitalWrite(7, HIGH);
break;
case 103:
digitalWrite(5, HIGH);
digitalWrite(6, HIGH);
digitalWrite(7, LOW);
break;
case 104:
digitalWrite(5, HIGH);
digitalWrite(6, HIGH);
digitalWrite(7, HIGH);
break;
}
}
}[/mw_shl_code]
App Inventor编程部分:
截图201903101558401934.png

wbzd123  学徒

发表于 2019-3-13 22:29:17

不错!
回复

使用道具 举报

粒子  超级版主

发表于 2019-3-14 18:45:48

回复

使用道具 举报

DFBJXU3LQi4  学徒

发表于 2019-6-6 23:01:59

这个小白看起来很牛
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

为本项目制作心愿单
购买心愿单
心愿单 编辑
[[wsData.name]]

硬件清单

  • [[d.name]]
btnicon
我也要做!
点击进入购买页面
上海智位机器人股份有限公司 沪ICP备09038501号-4

© 2013-2022 Comsenz Inc. Powered by Discuz! X3.4 Licensed

mail