当前位置:网站首页>L298N module use
L298N module use
2022-07-05 08:29:00 【Sharing master】
The module pin description is as follows :
notes : Built in 5V Power supply , There is no need to pick it up from the outside 5V Input

Input information :
ENA and ENB The pins of the words are respectively connected to support PWM Output any digital port , And passed in the program AnalogWrite() Statement to adjust the speed .

Schematic diagram of circuit connection :

Program :
/* *****************************************************************
* *****************************************************************
*
*
* *****************************************************************/
#define BLINKER_WIFI
#include <Blinker.h>
#define STOP 0
#define FORWARD 1
#define BACKWARD 2
#define TURNLEFT 3
#define TURNRIGHT 4
// Motor control pin
#define LEFT_MOTOR1 D1
#define LEFT_MOTOR2 D2
#define RIGHT_MOTOR1 D3
#define RIGHT_MOTOR2 D4
#define LEFT_ENA D7
#define RIGHT_ENB D8
char auth[] = "2168d525043de";
char ssid[] = "000";
char pswd[] = "000";
// New component object
BlinkerButton Button0("btn-abc");
BlinkerButton Button1("btn-abd");
BlinkerButton Button2("btn-abe");
BlinkerButton Button3("btn-abf");
BlinkerButton Button4("btn-abg");
BlinkerButton Button5("btn-all");
BlinkerNumber Number1("num-abc");
int cmd = 1;
int counter = 0;
// Press the key to execute the function
void button0_callback(const String & state)
{
BLINKER_LOG("get button0 state: ", state);
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
}
void button1_callback(const String & state) {
BLINKER_LOG("get button1 state: ", state);
motor_run(1);
Button1.print("on");
Button2.print("off");
Button3.print("off");
Button4.print("off");
}
void button2_callback(const String & state) {
BLINKER_LOG("get button2 state: ", state);
motor_run(2);
Button1.print("off");
Button2.print("on");
Button3.print("off");
Button4.print("off");
}
void button3_callback(const String & state) {
BLINKER_LOG("get button3 state: ", state);
motor_run(3);
Button1.print("off");
Button2.print("off");
Button3.print("on");
Button4.print("off");
}
void button4_callback(const String & state) {
BLINKER_LOG("get button4 state: ", state);
motor_run(4);
Button1.print("off");
Button2.print("off");
Button3.print("off");
Button4.print("on");
}
void button5_callback(const String & state) {
BLINKER_LOG("get button5 state: ", state);
Button1.print("off");
Button2.print("off");
Button3.print("off");
Button4.print("off");
motor_run(0);
digitalWrite(LEFT_MOTOR1, HIGH);
digitalWrite(LEFT_MOTOR2, HIGH);
digitalWrite(RIGHT_MOTOR1, HIGH);
digitalWrite(RIGHT_MOTOR2, HIGH);
}
// If unbound components are triggered , Then the content will be executed
void dataRead(const String & data)
{
BLINKER_LOG("Blinker readString: ", data);
counter++;
Number1.print(counter);
}
void setup()
{
// Initialize serial port
Serial.begin(115200);
BLINKER_DEBUG.stream(Serial);
// Initialization has LED Of IO
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, HIGH);
pinMode(LEFT_MOTOR1, OUTPUT);
pinMode(LEFT_MOTOR2, OUTPUT);
pinMode(RIGHT_MOTOR1, OUTPUT);
pinMode(RIGHT_MOTOR2, OUTPUT);
pinMode(LEFT_ENA,OUTPUT);
pinMode(RIGHT_ENB,OUTPUT);
// initialization blinker
Blinker.begin(auth, ssid, pswd);
Blinker.attachData(dataRead);
motor_run(STOP);
Button0.attach(button0_callback);
Button1.attach(button1_callback);
Button2.attach(button2_callback);
Button3.attach(button3_callback);
Button4.attach(button4_callback);
Button5.attach(button5_callback);
}
/* *****************************************************************
*
Motor control letter
*
* *****************************************************************/
int highSpeed = 200;
int lowSpeed = 100;
void motor_run(int cmd)
{
switch(cmd)
{
case FORWARD:
Serial.println("FORWARD"); // Output status
analogWrite(LEFT_ENA,highSpeed);
digitalWrite(LEFT_MOTOR1, LOW);
digitalWrite(LEFT_MOTOR2, HIGH);
analogWrite(RIGHT_ENB,highSpeed);
digitalWrite(RIGHT_MOTOR1, LOW);
digitalWrite(RIGHT_MOTOR2, HIGH);
break;
case BACKWARD:
Serial.println("BACKWARD"); // Output status
digitalWrite(LEFT_MOTOR1, HIGH);
digitalWrite(LEFT_MOTOR2, LOW);
digitalWrite(RIGHT_MOTOR1, HIGH);
digitalWrite(RIGHT_MOTOR2, LOW);
break;
case TURNLEFT:
Serial.println("TURN LEFT"); // Output status
analogWrite(LEFT_ENA,lowSpeed);
analogWrite(RIGHT_ENB,highSpeed);
digitalWrite(LEFT_MOTOR1, LOW);
digitalWrite(LEFT_MOTOR2, HIGH);//C
digitalWrite(RIGHT_MOTOR1, LOW);
digitalWrite(RIGHT_MOTOR2, HIGH);
break;
case TURNRIGHT:
Serial.println("TURN RIGHT"); // Output status
analogWrite(LEFT_ENA,highSpeed);
analogWrite(RIGHT_ENB,lowSpeed);
digitalWrite(LEFT_MOTOR1, LOW);
digitalWrite(LEFT_MOTOR2, HIGH);
digitalWrite(RIGHT_MOTOR1, LOW);//C
digitalWrite(RIGHT_MOTOR2, HIGH);
break;
case STOP:
default:
Serial.println("STOP"); // Output status
analogWrite(LEFT_ENA,1);
analogWrite(RIGHT_ENB,1);
digitalWrite(LEFT_MOTOR1, LOW);
digitalWrite(LEFT_MOTOR2, LOW);
digitalWrite(RIGHT_MOTOR1, LOW);
digitalWrite(RIGHT_MOTOR2, LOW);
break;
}
}
void loop() {
Blinker.run();
}
边栏推荐
- Sword finger offer 05 Replace spaces
- Wifi-802.11 negotiation rate table
- 亿学学堂给的证券账户安不安全?哪里可以开户
- Hardware 3 -- function of voltage follower
- 实例006:斐波那契数列
- 2020-05-21
- Hardware and software solution of FPGA key chattering elimination
- NTC thermistor application - temperature measurement
- Count the number of inputs (C language)
- leetcode - 445. 两数相加 II
猜你喜欢
![[paper reading] the latest transfer ability in deep learning: a survey in 2022](/img/6b/b564fb7a6895329073fb5eaff64340.png)
[paper reading] the latest transfer ability in deep learning: a survey in 2022

Summary of SIM card circuit knowledge

【云原生 | 从零开始学Kubernetes】三、Kubernetes集群管理工具kubectl

【NOI模拟赛】汁树(树形DP)

Array integration initialization (C language)

STM32 --- NVIC interrupt

H264 (I) i/p/b frame gop/idr/ and other parameters
![[trio basic tutorial 18 from introduction to proficiency] trio motion controller UDP fast exchange data communication](/img/05/0f63e4cd3da24e5b956ec5899b939d.jpg)
[trio basic tutorial 18 from introduction to proficiency] trio motion controller UDP fast exchange data communication

STM32 summary (HAL Library) - DHT11 temperature sensor (intelligent safety assisted driving system)

UE pixel stream, come to a "diet pill"!
随机推荐
My-basic application 1: introduction to my-basic parser
[trio basic tutorial 17 from getting started to mastering] set up and connect the trio motion controller and input the activation code
Google sitemap files for rails Projects - Google sitemap files for rails projects
实例007:copy 将一个列表的数据复制到另一个列表中。
[tutorial 19 of trio basic from introduction to proficiency] detailed introduction of trio as a slave station connecting to the third-party bus (anybus PROFIBUS DP...)
go依赖注入--google开源库wire
Example 008: 99 multiplication table
Soem EtherCAT source code analysis attachment 1 (establishment of communication operation environment)
Example 010: time to show
Void* C is a carrier for realizing polymorphism
Basic information commands and functions of kernel development
STM32 single chip microcomputer - external interrupt
Example 001: the number combination has four numbers: 1, 2, 3, 4. How many three digits can be formed that are different from each other and have no duplicate numbers? How many are each?
每日一题——替换空格
MHA High available Cluster for MySQL
On boost circuit
Management and use of DokuWiki (supplementary)
Example 003: a complete square is an integer. It is a complete square after adding 100, and it is a complete square after adding 168. What is the number?
关于线性稳压器的五个设计细节
Take you to understand the working principle of lithium battery protection board