5454| 3
|
[教程] App Inventor通过蓝牙控制Arduino RGB LED灯依次点亮 |
使用蓝牙模块HC-05与App Inventor通信。早期的帖子因为要给MIT写博客,所以app的界面及编程环境用的是英文。(请忽略俺凌乱的接线) 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编程部分: |
© 2013-2024 Comsenz Inc. Powered by Discuz! X3.4 Licensed