AppInventor2 SVIP会员 TA的每日心情![](source/plugin/dsu_paulsign/img/emot/yun.gif) | 晕~ 3 天前 |
---|
签到天数: 32 天 [LV.5]常住居民I
版主
![Rank: 7](https://bbs.tsingfun.com/static/image/common//star_level3.gif) ![Rank: 7](https://bbs.tsingfun.com/static/image/common//star_level2.gif) ![Rank: 7](https://bbs.tsingfun.com/static/image/common//star_level1.gif)
- 积分
- 1788
|
本节主要实现硬件参数上报,板子接收到指令,执行后反馈一个状态给APP。
1.界面组件
增加两个标签,一个布局,一个文本输入框
2.程序逻辑
增加接收处理和显示判断
3.arduino nano代码
- // 引脚定义
- const int ledPin1 = 5;// the number of the LED pin
- const int ledPin2 = 6;
- const int ledPin3 = 3;
- const int bluePin = 6;// the number of the LED pin
- const int greenPin = 5;
- const int redPin = 3;
- const int beepPin = 15;
- const int relayPin = 14;
- const int keyPin1 = 2;
- const int keyPin2 = 4;
- const int keyPin3 = 7;
- const int bluetoothPin = 13;
- // 变量定义
- int inByte=0; //接收参数
- #define TRUE 1
- #define FALSE 0
- void setup()
- {
- // 配置输出引脚
- pinMode(ledPin1, OUTPUT);
- pinMode(ledPin2, OUTPUT);
- pinMode(ledPin3, OUTPUT);
- pinMode(beepPin, OUTPUT);
- pinMode(relayPin, OUTPUT);
- // 配置输入引脚
- pinMode(keyPin1, INPUT);
- pinMode(keyPin2, INPUT);
- pinMode(keyPin3, INPUT);
- pinMode(bluetoothPin, INPUT);
- // 配置串口
- Serial.begin(9600);
- }
- void loop() {
- if(Serial.available()) {
- inByte = Serial.read();
-
- if(inByte == 'H'){
- digitalWrite(relayPin, HIGH);
- Serial.print("ON");
- }
- if(inByte == 'L'){
- digitalWrite(relayPin, LOW);
- Serial.print("OFF");
- }
-
- } }
复制代码
|
|