keyestudio WiKi
9.3.5.2 Code
Download codes: Codes
Download and unzip the file. Open the corresponding code file. Code file for Chapter 9.3.5.2 is named 9-3-5-2.
/*
Keyestudio ESP32 Robot Arm
9-3-5-2 tutorial code
Function: joystick controls arm, axis z stores the rotation angle and re-plays
action
http://www.keyestudio.com
*/
#include
"ESP32Servo.h"
Servo base;
// create servo object to control a servo
Servo arm;
Servo forearm;
Servo gripper;
//Define servo control pin
#define basePin 16
#define armPin 17
#define forearmPin 2
#define gripperPin 4
//Define left joystick pin
#define left_B 12
#define left_X 13
#define left_Y 15
//Define right joystick pin
#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;
int
attitude_data[4][11];
int
base_attitude
=
int
arm_attitude
=
1;
int
forearm_attitude
int
gripper_attitude
int
data_start_bit
=
int
data_end_bit
=
0;
void
setup() {
// put your setup code here, to run once:
pinMode(left_B, INPUT);
pinMode(left_X, INPUT);
140
// initialize base servo angle
// initialize upper arm servo angle
// initialize forearm servo angle
// initialize claw servo angle
0;
=
2;
=
3;
1;
(continues on next page)
Chapter 9. 9. Robot Arm Projects
the␣
Need help?
Do you have a question about the ESP32 and is the answer not in the manual?
Questions and answers