esp32-car/src/main.cpp

49 lines
922 B
C++

#include <Arduino.h>
#include "motor.h"
#include "utils.h"
#include "storage.h"
#include "ble.h"
#include "led.h"
#include "ir.h"
#include "consts.h"
void setup()
{
// 初始化口
Serial.begin(115200);
// 初始化 EEPROM
Storage::init();
// 初始化 BLE
BLEManager::init(Storage::getName());
// 初始化电机
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});
// 初始化红外循迹模块
IR::init({IR_MODE, IR_PINS});
// 初始化状态灯
if (STATUS_LED_ENABLE)
{
LED::init(STATUS_LED);
}
}
void loop()
{
IR::update();
if (STATUS_LED_ENABLE)
{
LED::updateStatusLED(BLEManager::deviceConnected);
}
if (BLEManager::deviceConnected)
{
sendStatus(*BLEManager::pTxCharacteristic);
}
}