| 
 | 
 
本节主要实现硬件参数上报,板子接收到指令,执行后反馈一个状态给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");  
 
 -     } 
 
 -     
 
 -   } }
 
 
  复制代码 
 
 |   
 
 
 
 |