文件下载链接:L298N驱动原理图+PCB文件
文件下载链接:L298N驱动原理图+PCB文件
点击下载即可
右上角这种一模一样的驱动,亲测可用!
AD的3D截图,L298N的3D没有模型,实际上是一样的。
PCB走线
多看几张3D图吧,如果文件或者原理图有错,请你打死我,谢谢
如果文件或者原理图有错,请你打死我,谢谢
如果文件或者原理图有错,请你打死我,谢谢
如果文件或者原理图有错,请你打死我,谢谢
按下就走,松手就停,还附带了转弯调速
```c
#define BLINKER_PRINT Serial
#define BLINKER_WIFI
//#define BLINKER_ESP_SMARTCONFIG//
#include <Blinker.h>
char auth[] = "92acbbb54aff";
char ssid[] = "c2580";
char pswd[] = "ran7758258";
#define BUTTON_1 "b1"
#define BUTTON_2 "b2"
#define BUTTON_3 "b3"
#define BUTTON_4 "b4"
#define BUTTON_5 "b5"
#define BUTTON_6 "b6"
#define BUTTON_7 "b7"
#define BUTTON_8 "b8"
#define BUTTON_9 "b9"
#define slider_0 "r1"
#define slider_1 "r2"
BlinkerButton Button1(BUTTON_1);
BlinkerButton Button2(BUTTON_2);
BlinkerButton Button3(BUTTON_3);
BlinkerButton Button4(BUTTON_4);
BlinkerButton Button5(BUTTON_5);
BlinkerButton Button6(BUTTON_6);
BlinkerButton Button7(BUTTON_7);
BlinkerButton Button8(BUTTON_8);
BlinkerButton Button9(BUTTON_9);
BlinkerSlider Slider0(slider_0);
BlinkerSlider Slider1(slider_1);
int pwm1=60;//转向速度
int pwm2=60;//转向速度
int flag;//判断当前状态
//16和5在左侧,4和2在右侧
//16前进,4前进
//5后退,2后退
void button1_callback(const String &state)
{
digitalWrite(12, LOW);
}
/*void button2_callback(const String &state)//前进
{
BLINKER_LOG("get button state: ", state);
if (state != "pressup")
{
flag=1;
analogWrite(16, pwm1);
digitalWrite(5, LOW);
analogWrite(4, pwm2);
digitalWrite(2, LOW);
}
}*/
/*/中短线///*/
void button2_callback(const String &state)//前进,按下有效的改进
{
if (state == BLINKER_CMD_BUTTON_PRESSED)
{
digitalWrite(16, pwm1);
analogWrite(5, LOW);
analogWrite(4, pwm2);
digitalWrite(2, LOW);
}
else if (state == BLINKER_CMD_BUTTON_PRESSUP)
{
digitalWrite(16, HIGH);
digitalWrite(5, HIGH);
digitalWrite(4, HIGH);
digitalWrite(2, HIGH);
}
}
void button3_callback(const String &state) //垃圾袋开
{
digitalWrite(13, LOW);
}
/*void button4_callback(const String &state)//按下一直在左转
{
digitalWrite(16, LOW);//digitalWrite(pin,value)函数它的作用是设置引脚的输出的电压为高电平或低电平。注意:在使用digitalWrite(pin, value)函数设置引脚之前,需要将引脚设置为OUTPUT模式
analogWrite(5, pwm1);//左退,Arduino每一次对引脚执行analogWrite()指令,都会给该引脚一个固定频率的PWM信号。PWM信号的频率大约为490Hz.
analogWrite(4, pwm2);//右进
digitalWrite(2, LOW);
flag=3;
}*/
void button4_callback(const String &state)//左转,按下有效的改进
{
if (state == BLINKER_CMD_BUTTON_PRESSED)
{
digitalWrite(16, LOW);
analogWrite(5, pwm1);
analogWrite(4, pwm2);
digitalWrite(2, LOW);
}
else if (state == BLINKER_CMD_BUTTON_PRESSUP)
{
digitalWrite(16, HIGH);
digitalWrite(5, HIGH);
digitalWrite(4, HIGH);
digitalWrite(2, HIGH);
}
}
void button5_callback(const String &state)//停止
{
BLINKER_LOG("get button state: ", state);
if (state != "pressup")
{
digitalWrite(16, HIGH);
digitalWrite(5, HIGH);
digitalWrite(4, HIGH);
digitalWrite(2, HIGH);
flag=5;
}
}
/*void button6_callback(const String &state)//右转
{
BLINKER_LOG("get button state: ", state);
if (state != "pressup")
{
analogWrite(16, pwm1);
digitalWrite(5,LOW);
digitalWrite(4, LOW);
analogWrite(2,pwm2);
flag=4;
}
}*/
void button6_callback(const String &state)//右转,按下有效的改进
{
if (state == BLINKER_CMD_BUTTON_PRESSED)
{
digitalWrite(16, pwm1);
analogWrite(5, LOW);
analogWrite(4, LOW);
digitalWrite(2, pwm2);
}
else if (state == BLINKER_CMD_BUTTON_PRESSUP)
{
digitalWrite(16, HIGH);
digitalWrite(5, HIGH);
digitalWrite(4, HIGH);
digitalWrite(2, HIGH);
}
}
void button7_callback(const String &state)//毛刷关
{
digitalWrite(12, HIGH);
}
/*void button8_callback(const String &state)//后退
{
BLINKER_LOG("get button state: ", state);
if (state != "pressup")
{
digitalWrite(16, LOW);
analogWrite(5,pwm1);
digitalWrite(4, LOW);
analogWrite(2,pwm2);
flag=2;
}
}
*/
void button8_callback(const String &state)//后退,按下有效的改进
{
if (state == BLINKER_CMD_BUTTON_PRESSED)
{
digitalWrite(16, LOW);
analogWrite(5, pwm1);
analogWrite(4, LOW);
digitalWrite(2, pwm2);
}
else if (state == BLINKER_CMD_BUTTON_PRESSUP)
{
digitalWrite(16, HIGH);
digitalWrite(5, HIGH);
digitalWrite(4, HIGH);
digitalWrite(2, HIGH);
}
}
void button9_callback(const String &state)//垃圾袋关
{
BLINKER_LOG("get button state: ", state);
if (state != "pressup")
{
digitalWrite(13, HIGH);
}
}
void slider0_callback(int32_t value) //以下为PWM1方向调参
{
BLINKER_LOG("slider:", value);
pwm1=value;
switch(flag)
{
case 1: analogWrite(16, pwm1); break;
case 2: analogWrite(5, pwm1); break;
case 3: analogWrite(5, pwm1); break;
case 4: analogWrite(16, pwm1); break;
case 5: break;
default:break;
}
}
void slider1_callback(int32_t value) //以下为PWM2方向调参
{
BLINKER_LOG("slider:", value);
pwm2=value;
switch(flag)
{
case 1: analogWrite(4, pwm2); break;
case 2: analogWrite(2, pwm2); break;
case 3: analogWrite(2, pwm2); break;
case 4: analogWrite(4, pwm2); break;
case 5: break;
default:break;
}
}
//blinker初始化
void blinker_car_init()
{
//1-4号引脚设置为输出模式
pinMode(16, OUTPUT);//
pinMode(5, OUTPUT);//
pinMode(4, OUTPUT);//
pinMode(2, OUTPUT);//
pinMode(12, OUTPUT);//
pinMode(13, OUTPUT);//
}
void setup()
{
digitalWrite(D0, HIGH);
digitalWrite(D1, HIGH);
digitalWrite(D2, HIGH);
digitalWrite(D4, HIGH);
analogWriteRange(100);
analogWriteFreq(50);
//analogWrite(D2, 50);//0-100 50
//初始化小车参数
blinker_car_init();
//按钮绑定
Button1.attach(button1_callback);
Button2.attach(button2_callback);
Button3.attach(button3_callback);
Button4.attach(button4_callback);
Button5.attach(button5_callback);
Button6.attach(button6_callback);
Button7.attach(button7_callback);
Button8.attach(button8_callback);
Button9.attach(button9_callback);
Slider0.attach(slider0_callback);
Slider1.attach(slider1_callback);
Blinker.begin(auth,ssid,pswd);
// Blinker.begin(auth);
}
void loop()
{
Blinker.run();
}