esp32-car/src/main.cpp

38 lines
777 B
C++
Raw Normal View History

2024-12-12 15:38:11 +08:00
#include <Arduino.h>
2024-12-27 09:47:56 +08:00
#include <motor.h>
#include <utils.h>
#include <storage.h>
#include <ble.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
BLEManager::init(DEVICE_NAME);
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-12 15:38:11 +08:00
// 设置引脚模式
2024-12-15 18:09:40 +08:00
pinMode(STATUS_LED, OUTPUT);
digitalWrite(STATUS_LED, HIGH);
2024-12-19 01:08:39 +08:00
}
2024-12-15 18:09:40 +08:00
void loop()
{
2024-12-27 09:47:56 +08:00
updateStatusLED(BLEManager::deviceConnected, STATUS_LED);
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
}
}