main
This commit is contained in:
86
src/main.cpp
86
src/main.cpp
@ -93,7 +93,7 @@ void printSensorData() {
|
||||
switch (sensor_data.height_sta) {
|
||||
case 0x00: Serial.println("No Device"); break;
|
||||
case 0x01: Serial.println("Power Off"); break;
|
||||
case 0x02: Serial.println("Valid"); break;
|
||||
case 0x03: Serial.println("Valid"); break;
|
||||
default: Serial.println("Unknown"); break;
|
||||
}
|
||||
|
||||
@ -111,53 +111,55 @@ void setup() {
|
||||
Wire.begin(1,2);
|
||||
|
||||
Serial.println("I2C Master Started...");
|
||||
delay(1000);
|
||||
delay(500);
|
||||
}
|
||||
|
||||
// void loop() {
|
||||
|
||||
// // 请求传感器数据
|
||||
// if (requestData()) {
|
||||
// printSensorData();
|
||||
// }
|
||||
|
||||
// delay(2000);
|
||||
|
||||
// // sendCommand(0x02);
|
||||
// // delay(2000);
|
||||
// // sendCommand(0x04);
|
||||
// }
|
||||
|
||||
#define INTERVAL 5000
|
||||
|
||||
unsigned long previousMillis = 0; // 上次执行的时间点
|
||||
bool isGpsOn = true; // GPS 状态标志
|
||||
|
||||
void loop() {
|
||||
unsigned long currentMillis = millis();
|
||||
|
||||
// 检查是否达到时间间隔
|
||||
if (currentMillis - previousMillis >= INTERVAL) {
|
||||
previousMillis = currentMillis;
|
||||
|
||||
// 切换状态
|
||||
if (isGpsOn) {
|
||||
sendCommand(CMD_GPS_POWER_OFF); // 关闭 GPS
|
||||
sendCommand(CMD_RANGING_POWER_OFF); // 关闭测距
|
||||
Serial.println("CLOSE...");
|
||||
} else {
|
||||
sendCommand(CMD_GPS_POWER_ON); // 开启 GPS
|
||||
sendCommand(CMD_RANGING_POWER_ON); // 开启测距
|
||||
Serial.println("OPEN...");
|
||||
}
|
||||
|
||||
isGpsOn = !isGpsOn; // 翻转状态
|
||||
}
|
||||
|
||||
// 请求传感器数据并打印
|
||||
// 请求传感器数据
|
||||
if (requestData()) {
|
||||
printSensorData();
|
||||
}
|
||||
delay(1500);
|
||||
|
||||
delay(1000);
|
||||
|
||||
// sendCommand(0x02);
|
||||
// delay(2000);
|
||||
// sendCommand(0x04);
|
||||
}
|
||||
|
||||
|
||||
// ******命令测试************
|
||||
// #define INTERVAL 5000
|
||||
|
||||
// unsigned long previousMillis = 0; // 上次执行的时间点
|
||||
// bool isGpsOn = true; // GPS 状态标志
|
||||
|
||||
// void loop() {
|
||||
// unsigned long currentMillis = millis();
|
||||
|
||||
// // 检查是否达到时间间隔
|
||||
// if (currentMillis - previousMillis >= INTERVAL) {
|
||||
// previousMillis = currentMillis;
|
||||
|
||||
// // 切换状态
|
||||
// if (isGpsOn) {
|
||||
// sendCommand(CMD_GPS_POWER_OFF); // 关闭 GPS
|
||||
// sendCommand(CMD_RANGING_POWER_OFF); // 关闭测距
|
||||
// Serial.println("CLOSE...");
|
||||
// } else {
|
||||
// sendCommand(CMD_GPS_POWER_ON); // 开启 GPS
|
||||
// sendCommand(CMD_RANGING_POWER_ON); // 开启测距
|
||||
// Serial.println("OPEN...");
|
||||
// }
|
||||
|
||||
// isGpsOn = !isGpsOn; // 翻转状态
|
||||
// }
|
||||
|
||||
// // 请求传感器数据并打印
|
||||
// if (requestData()) {
|
||||
// printSensorData();
|
||||
// }
|
||||
// delay(1500);
|
||||
// }
|
||||
|
||||
|
Reference in New Issue
Block a user