keyestudio WiKi
9.3.3 9.3.3 Test Code
Download codes: Codes
Download and unzip the file. Open the corresponding code file. Code file for Chapter 9.3.3 is named 9-3-3.
/*
Keyestudio ESP32 Robot Arm
9-3-3 tutorial code
Function: joystick control the robot arm
http://www.keyestudio.com
*/
#include
"ESP32Servo.h"
Servo base;
// create servo object to control a servo
Servo arm;
Servo forearm;
Servo gripper;
//set servo control pins
#define basePin 16
#define armPin 17
#define forearmPin 2
#define gripperPin 4
//set left joystick pins
#define left_B 12
#define left_X 13
#define left_Y 15
//set right joystick pins
#define right_B 25
#define right_X 33
#define right_Y 32
int
left_B_data, left_Y_data, left_X_data, right_B_data, right_X_data, right_Y_data;
//servo
int
baseAngle
=
90;
int
armAngle
=
90;
int
forearmAngle
=
90;
int
gripperAngle
=
90;
void
setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(left_B, INPUT);
pinMode(left_X, INPUT);
pinMode(left_Y, INPUT);
pinMode(right_B, INPUT);
pinMode(right_X, INPUT);
pinMode(right_Y, INPUT);
base.attach(basePin);
arm.attach(armPin);
forearm.attach(forearmPin);
134
// Initialize bottom servo angle
// Initialize upper arm servo angle
// Initialize forearm servo angle
// Initialize claw servo angle
// attaches the servo on pin 16 to the servo object
(continues on next page)
Chapter 9. 9. Robot Arm Projects
Need help?
Do you have a question about the ESP32 and is the answer not in the manual?
Questions and answers