diff --git a/include/consts.example.h b/include/consts.example.h index a1119b0..e7b80f0 100644 --- a/include/consts.example.h +++ b/include/consts.example.h @@ -2,6 +2,7 @@ #define __CONSTS_H__ #define STATUS_LED 2 +#define STATUS_LED_ENABLE 1 #define DEVICE_NAME "WhiteTiger" diff --git a/include/led.h b/include/led.h new file mode 100644 index 0000000..d28dd73 --- /dev/null +++ b/include/led.h @@ -0,0 +1,14 @@ +#ifndef __LED_H__ +#define __LED_H__ + +#include + +class LED +{ +public: + static int ledPin; + static void init(int pin); + static void updateStatusLED(bool status); +}; + +#endif // __LED_H__ \ No newline at end of file diff --git a/src/led.cpp b/src/led.cpp new file mode 100644 index 0000000..a9d9e9a --- /dev/null +++ b/src/led.cpp @@ -0,0 +1,15 @@ +#include "led.h" + +int LED::ledPin = 0; + +void LED::init(int pin) +{ + ledPin = pin; + pinMode(ledPin, OUTPUT); + digitalWrite(ledPin, HIGH); +} + +void LED::updateStatusLED(bool status) +{ + digitalWrite(ledPin, status); +} \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 8bf81e6..6d86a73 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,8 +1,9 @@ #include -#include -#include -#include -#include +#include "motor.h" +#include "utils.h" +#include "storage.h" +#include "ble.h" +#include "led.h" #include "consts.h" void setup() @@ -23,14 +24,19 @@ void setup() {MOTOR_C_PWMA, MOTOR_C_AIN1, MOTOR_C_AIN2}, {MOTOR_D_PWMB, MOTOR_D_BIN1, MOTOR_D_BIN2}); - // 设置引脚模式 - pinMode(STATUS_LED, OUTPUT); - digitalWrite(STATUS_LED, HIGH); + // 初始化状态灯 + if (STATUS_LED_ENABLE) + { + LED::init(STATUS_LED); + } } void loop() { - updateStatusLED(BLEManager::deviceConnected, STATUS_LED); + if (STATUS_LED_ENABLE) + { + LED::updateStatusLED(BLEManager::deviceConnected); + } if (BLEManager::deviceConnected) { sendStatus(*BLEManager::pTxCharacteristic);