esp32-car/src/main.cpp

44 lines
824 B
C++
Raw Normal View History

2024-12-12 15:38:11 +08:00
#include <Arduino.h>
2024-12-27 09:57:09 +08:00
#include "motor.h"
#include "utils.h"
#include "storage.h"
#include "ble.h"
#include "led.h"
2024-12-18 14:16:02 +08:00
#include "consts.h"
2024-12-15 18:09:40 +08:00
2024-12-12 15:38:11 +08:00
void setup()
{
2024-12-19 19:48:52 +08:00
// 初始化口
2024-12-12 15:38:11 +08:00
Serial.begin(115200);
2024-12-15 18:09:40 +08:00
2024-12-18 16:10:26 +08:00
// 初始化 EEPROM
2024-12-27 09:47:56 +08:00
Storage::init();
2024-12-27 09:52:50 +08:00
// 初始化 BLE
2024-12-27 10:16:08 +08:00
BLEManager::init(Storage::getName());
2024-12-27 09:52:50 +08:00
2024-12-27 09:47:56 +08:00
// 初始化电机
MotorController::init(
{MOTOR_A_PWMA, MOTOR_A_AIN1, MOTOR_A_AIN2},
{MOTOR_B_PWMB, MOTOR_B_BIN1, MOTOR_B_BIN2},
{MOTOR_C_PWMA, MOTOR_C_AIN1, MOTOR_C_AIN2},
{MOTOR_D_PWMB, MOTOR_D_BIN1, MOTOR_D_BIN2});
2024-12-18 16:10:26 +08:00
2024-12-27 09:57:09 +08:00
// 初始化状态灯
if (STATUS_LED_ENABLE)
{
LED::init(STATUS_LED);
}
2024-12-19 01:08:39 +08:00
}
2024-12-15 18:09:40 +08:00
void loop()
{
2024-12-27 09:57:09 +08:00
if (STATUS_LED_ENABLE)
{
LED::updateStatusLED(BLEManager::deviceConnected);
}
2024-12-27 09:47:56 +08:00
if (BLEManager::deviceConnected)
2024-12-19 01:08:39 +08:00
{
2024-12-27 09:47:56 +08:00
sendStatus(*BLEManager::pTxCharacteristic);
2024-12-19 01:08:39 +08:00
}
}