Bill of Material:
直流马达(<9V, 2A) x2, 底盘 x1,9V电池 x1, 电池扣 x1, 摇杆模块 x1, L298N 马达驱动模块 x1, Arduino Uno x1, 面包板线。
.演示视频,拼装教程:
Arduino机器人快速上手经验分享
接线图
程式/代码:
/*
Demonstrates the use of Joystick control with Arduino UNO and L298N Motor Driver MOdule.
Last Edited: Jan.4th.2020 by Mun Kim
*/
int in1 = 3; // Direction Control: Motor 1(Left Hand Side)
int in2 = 4; // Direction Control: Motor 1(Left Hand Side)
int enA = 5; // Power Control: Motor 1
int in3 = 7; // Direction Control: Motor 2 (Right Hand Side)
int in4 = 8; // Direction Control: Motor 2 (Right Hand Side)
int enB = 9; // Power Control: Motor 2
int MotorSpeed1 = 0; // Motor 1 Speed Values - Start at zero
int MotorSpeed2 = 0; // Motor 2 Speed Values - Start at zero
int joyHorz = A0; // Joystick Input: Horizontal(X-axis)
int joyVert = A1; // Joystick Input: Vertical(Y-axis)
// Joystick Values - Start at 512 (middle position)
int joyposVert = 512;
int joyposHorz = 512;</