这一节介绍实现多个参数上传,在上一节基础上增加温度参数和电位计参数
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 sendPara(void)
{
unsigned int temp;
if(inByte == 'H'){
digitalWrite(relayPin, HIGH);
Serial.print("ON");
}
if(inByte == 'L'){
digitalWrite(relayPin, LOW);
Serial.print("OFF");
}
Serial.print("|");
temp = random(10,80);
Serial.print(temp);
Serial.print("|");
temp = random(0,1023);
Serial.print(temp);
Serial.print("|");
}
void loop() {
if(Serial.available()) {
inByte = Serial.read();
}delay(1000);
sendPara();
}
}
4.后续扩展,还可以添加更多的参数。