引脚 | 定义 |
---|---|
VM | 驱动电压输入端(3-12V) |
VCC | 逻辑电平输入端(2.7-5.5) |
GND | 电源地端 |
STBY | 正常工作/待机状态控制输入端 |
PWMA | PWM信号输入端 |
AIN1、AIN2 | 电机A控制模式输入端 |
A01、A02 | 电机A驱动输入端 |
PWMB | PWM信号输入端 |
BIN1、BIN2 | 电机B控制模式输入端 |
B01、B02 | 电机B驱动输出端 |
int STBY = 10; //standby
//Motor A
int PWMA = 3; //Speed control
int AIN1 = 9; //Direction
int AIN2 = 8; //Direction
//Motor B
int PWMB = 5; //Speed control
int BIN1 = 11; //Direction
int BIN2 = 12; //Direction
/*
* Move specific motor at speed and direction
* motor: 0 for B, 1 for A
* speed: 0 is off, and 255 is full speed
* direction: 0 clockwise, 1 counter-clockwise
*/
void move(int motor, int speed, int direction){
digitalWrite(STBY, HIGH); //disable standby
boolean inPin1 = LOW;
boolean inPin2 = HIGH;
if(direction == 1){
inPin1 = HIGH;
inPin2 = LOW;
}
if(motor == 1){
digitalWrite(AIN1, inPin1);
digitalWrite(AIN2, inPin2);
analogWrite(PWMA, speed);
}else{
digitalWrite(BIN1, inPin1);
digitalWrite(BIN2, inPin2);
analogWrite(PWMB, speed);
}
}
void stop(){
digitalWrite(STBY, LOW);
}
void setup(){
pinMode(STBY, OUTPUT);
pinMode(PWMA, OUTPUT);
pinMode(AIN1, OUTPUT);
pinMode(AIN2, OUTPUT);
pinMode(PWMB, OUTPUT);
pinMode(BIN1, OUTPUT);
pinMode(BIN2, OUTPUT);
}
void loop(){
move(1, 255, 1); //motor 1, full speed, left
move(2, 255, 1); //motor 2, full speed, left
delay(1000); //go for 1 second
stop(); //stop
delay(250); //hold for 250ms until move again
move(1, 128, 0); //motor 1, half speed, right
move(2, 128, 0); //motor 2, half speed, right
delay(1000);
stop();
delay(250);
}
PID控制算法是结合比例、积分和微分三种环节于一体的控制算法,它是连续系统中技术最为成熟、应用最为广泛的一种控制算法。
ESP32系列(包括ESP32-S3)搭载Xtensa双核处理器,默认情况下Arduino框架仅使用单核运行用户代码,通过多核编程,可以充分利用硬件资源来提升系统响应和性能。
在本文中,先解释 MSB(最高有效位)和 LSB(最低有效位)的概念,以及 MSBFIRST 和 LSBFIRST。然后展示了 MSBFIRST 和 LSBFIRST 的使用如何影响移位寄存器的输出。
Arduino-ESP32项目提供的Preferences库是一个专为ESP32设计的非易失性存储解决方案,它替代了传统的Arduino EEPROM库,提供了更强大、更可靠的数据存储功能。
在Arduino中,通过串行端口接收数字通常涉及使用Serial.read()、Serial.readString()、Serial.parseInt()等方法。
要生成随机数,可以使用Arduino随机数函数random()。
本文收集整理在Arduino环境下字符串的相关用法,供参考。
ESP32在Arduino中的GPIO模式。
ESP32EA-MOC 开发板介绍和Arduino环境配置。