Mình bị lỗi này mà không biết sửa sao: redefinition of 'PS2X ps2x'
// PS2 Tank by Igor Fonseca @2019
// Controls a robotic tank using a PS2 joystick, using D-pad buttons
// based on an example using the PS2X library by Bill Porter 2011
// All text above must be included in any redistribution.
// include libraries
#include <PS2X_lib.h>
// These are used to set the direction of the bridge driver.
#define ENA 3      //ENA
#define MOTORA_1 4 //IN3
#define MOTORA_2 5 //IN4
#define MOTORB_1 8 //IN1
#define MOTORB_2 7 //IN2
#define ENB 6      //ENB
PS2X ps2x; // create PS2 Controller Class
//right now, the library does NOT support hot pluggable controllers, meaning 
//you must always either restart your Arduino after you conect the controller, 
//or call config_gamepad(pins) again after connecting the controller.
int error = 0; 
byte type = 0;
byte vibrate = 0;
void setup(){
 // Configure output pins
 pinMode(ENA, OUTPUT);
 pinMode(MOTORA_1, OUTPUT);
 pinMode(MOTORA_2, OUTPUT);
 pinMode(ENB, OUTPUT);
 pinMode(MOTORB_1, OUTPUT);
 pinMode(MOTORB_2, OUTPUT);
 // Disable both motors
 digitalWrite(ENA,0);
 digitalWrite(ENB,0);
 // Start serial communication
 Serial.begin(57600);
  
 error = ps2x.config_gamepad(13,11,10,12, true, true);   //setup pins and settings:  GamePad(clock, command, attention, data, Pressures?, Rumble?) check for error
 // Check for error
 if(error == 0){
  Serial.println("Found Controller, configured successful");
 }
   
 else if(error == 1)
  Serial.println("No controller found, check wiring or reset the Arduino");
   
 else if(error == 2)
  Serial.println("Controller found but not accepting commands");
  
 else if(error == 3)
  Serial.println("Controller refusing to enter Pressures mode, may not support it.");
   
 // Check for the type of controller
 type = ps2x.readType();
 switch(type) {
  case 0:
    Serial.println("Unknown Controller type");
    break;
  case 1:
    Serial.println("DualShock Controller Found");
    break;
  case 2:
    Serial.println("GuitarHero Controller Found");
    break;
  }
}
// Main loop
void loop(){
   
 if(error == 1) //skip loop if no controller found
  return; 
  
 else { //DualShock Controller
  
    ps2x.read_gamepad(false, vibrate); // disable vibration of the controller
    int nJoyL = ps2x.Analog(PSS_LY); // read left stick
    int nJoyR = ps2x.Analog(PSS_RY); // read right stick
   
    nJoyL = map(nJoyL, 0, 255, 1023, -1023);
    nJoyR = map(nJoyR, 0, 255, -1023, 1023);
    // Perform movements based on both analog sticks
     if(nJoyR>50) {
        digitalWrite(MOTORA_1,HIGH);
        digitalWrite(MOTORA_2,LOW);
        analogWrite(ENA, 1023);
     }
     if(nJoyR<-50) {
        digitalWrite(MOTORA_1,LOW);
        digitalWrite(MOTORA_2,HIGH);
        analogWrite(ENA, 1023);
     }
     if (abs(nJoyR)<50) {
        analogWrite(ENA, 0);
     }
     
     if(nJoyL>50) {
        digitalWrite(MOTORB_1,HIGH);
        digitalWrite(MOTORB_2,LOW);
        analogWrite(ENB, 1023);
     }
     if(nJoyL<-50) {
        digitalWrite(MOTORB_1,LOW);
        digitalWrite(MOTORB_2,HIGH);
        analogWrite(ENB, 1023);
     }
     if (abs(nJoyL)<50) {
        analogWrite(ENB, 0);
     }     
 delay(50);
 }    
}
            




Arduino: 1.8.19 (Windows 10), Board: "Arduino Uno"
Dpad:17:6: error: redefinition of 'PS2X ps2x'
PS2X ps2x; // create PS2 Controller Class
^~~~
In file included from C:\Users\Welcome\AppData\Local\Temp\Rar$DIa0.343\MakerBotwPS2\MakerBotwPS2.ino:2:0:
C:\Users\Welcome\AppData\Local\Temp\Rar$DIa0.343\MakerBotwPS2\PS2_controller.h:4:6: note: 'PS2X ps2x' previously declared here
PS2X ps2x; // create PS2 Controller Class
^~~~
C:\Users\Welcome\AppData\Local\Temp\Rar$DIa0.343\MakerBotwPS2\Dpad.ino: In function 'void setup()':
Dpad:26:6: error: redefinition of 'void setup()'
void setup(){
^~~~~
C:\Users\Welcome\AppData\Local\Temp\Rar$DIa0.343\MakerBotwPS2\MakerBotwPS2.ino:4:6: note: 'void setup()' previously defined here
void setup()
^~~~~
C:\Users\Welcome\AppData\Local\Temp\Rar$DIa0.343\MakerBotwPS2\Dpad.ino: In function 'void loop()':
Dpad:75:6: error: redefinition of 'void loop()'
void loop(){
^~~~
C:\Users\Welcome\AppData\Local\Temp\Rar$DIa0.343\MakerBotwPS2\MakerBotwPS2.ino:12:6: note: 'void loop()' previously defined here
void loop()
^~~~
C:\Users\Welcome\AppData\Local\Temp\Rar$DIa0.343\MakerBotwPS2\L2R2.ino: At global scope:
L2R2:20:6: error: redefinition of 'PS2X ps2x'
PS2X ps2x; // create PS2 Controller Class
^~~~
In file included from C:\Users\Welcome\AppData\Local\Temp\Rar$DIa0.343\MakerBotwPS2\MakerBotwPS2.ino:2:0:
C:\Users\Welcome\AppData\Local\Temp\Rar$DIa0.343\MakerBotwPS2\PS2_controller.h:4:6: note: 'PS2X ps2x' previously declared here
PS2X ps2x; // create PS2 Controller Class
^~~~
L2R2:25:5: error: redefinition of 'int error'
int error = 0;
^~~~~
C:\Users\Welcome\AppData\Local\Temp\Rar$DIa0.343\MakerBotwPS2\Dpad.ino:22:5: note: 'int error' previously defined here
int error = 0;
^~~~~
L2R2:26:6: error: redefinition of 'byte type'
byte type = 0;
^~~~
C:\Users\Welcome\AppData\Local\Temp\Rar$DIa0.343\MakerBotwPS2\Dpad.ino:23:6: note: 'byte type' previously defined here
byte type = 0;
^~~~
L2R2:27:6: error: redefinition of 'byte vibrate'
byte vibrate = 0;
^~~~~~~
C:\Users\Welcome\AppData\Local\Temp\Rar$DIa0.343\MakerBotwPS2\Dpad.ino:24:6: note: 'byte vibrate' previously defined here
byte vibrate = 0;
^~~~~~~
C:\Users\Welcome\AppData\Local\Temp\Rar$DIa0.343\MakerBotwPS2\L2R2.ino: In function 'void setup()':
L2R2:29:6: error: redefinition of 'void setup()'
void setup(){
^~~~~
C:\Users\Welcome\AppData\Local\Temp\Rar$DIa0.343\MakerBotwPS2\MakerBotwPS2.ino:4:6: note: 'void setup()' previously defined here
void setup()
^~~~~
C:\Users\Welcome\AppData\Local\Temp\Rar$DIa0.343\MakerBotwPS2\L2R2.ino: In function 'void loop()':
L2R2:78:6: error: redefinition of 'void loop()'
void loop(){
^~~~
C:\Users\Welcome\AppData\Local\Temp\Rar$DIa0.343\MakerBotwPS2\MakerBotwPS2.ino:12:6: note: 'void loop()' previously defined here
void loop()
^~~~
C:\Users\Welcome\AppData\Local\Temp\Rar$DIa0.343\MakerBotwPS2\LAnalog.ino: At global scope:
LAnalog:17:5: error: redefinition of 'int motor_right_speed'
int motor_right_speed = 0;
^~~~~~~~~~~~~~~~~
C:\Users\Welcome\AppData\Local\Temp\Rar$DIa0.343\MakerBotwPS2\L2R2.ino:17:5: note: 'int motor_right_speed' previously defined here
int motor_right_speed = 0;
^~~~~~~~~~~~~~~~~
LAnalog:18:5: error: redefinition of 'int motor_left_speed'
int motor_left_speed = 0;
^~~~~~~~~~~~~~~~
C:\Users\Welcome\AppData\Local\Temp\Rar$DIa0.343\MakerBotwPS2\L2R2.ino:18:5: note: 'int motor_left_speed' previously defined here
int motor_left_speed = 0;
^~~~~~~~~~~~~~~~
LAnalog:20:6: error: redefinition of 'PS2X ps2x'
PS2X ps2x; // create PS2 Controller Class
^~~~
In file included from C:\Users\Welcome\AppData\Local\Temp\Rar$DIa0.343\MakerBotwPS2\MakerBotwPS2.ino:2:0:
C:\Users\Welcome\AppData\Local\Temp\Rar$DIa0.343\MakerBotwPS2\PS2_controller.h:4:6: note: 'PS2X ps2x' previously declared here
PS2X ps2x; // create PS2 Controller Class
^~~~
LAnalog:25:5: error: redefinition of 'int error'
int error = 0;
^~~~~
C:\Users\Welcome\AppData\Local\Temp\Rar$DIa0.343\MakerBotwPS2\Dpad.ino:22:5: note: 'int error' previously defined here
int error = 0;
^~~~~
LAnalog:26:6: error: redefinition of 'byte type'
byte type = 0;
^~~~
C:\Users\Welcome\AppData\Local\Temp\Rar$DIa0.343\MakerBotwPS2\Dpad.ino:23:6: note: 'byte type' previously defined here
byte type = 0;
^~~~
LAnalog:27:6: error: redefinition of 'byte vibrate'
byte vibrate = 0;
^~~~~~~
C:\Users\Welcome\AppData\Local\Temp\Rar$DIa0.343\MakerBotwPS2\Dpad.ino:24:6: note: 'byte vibrate' previously defined here
byte vibrate = 0;
^~~~~~~
C:\Users\Welcome\AppData\Local\Temp\Rar$DIa0.343\MakerBotwPS2\LAnalog.ino: In function 'void setup()':
LAnalog:29:6: error: redefinition of 'void setup()'
void setup(){
^~~~~
C:\Users\Welcome\AppData\Local\Temp\Rar$DIa0.343\MakerBotwPS2\MakerBotwPS2.ino:4:6: note: 'void setup()' previously defined here
void setup()
^~~~~
C:\Users\Welcome\AppData\Local\Temp\Rar$DIa0.343\MakerBotwPS2\LAnalog.ino: In function 'void loop()':
LAnalog:78:6: error: redefinition of 'void loop()'
void loop(){
^~~~
Multiple libraries were found for "PS2X_lib.h"
C:\Users\Welcome\AppData\Local\Temp\Rar$DIa0.343\MakerBotwPS2\MakerBotwPS2.ino:12:6: note: 'void loop()' previously defined here
Used: C:\Users\Welcome\Documents\Arduino\libraries\PS2X_lib-master
void loop()
Not used: C:\Users\Welcome\Documents\Arduino\libraries\Arduino-PS2X-ESP32-Makerbot-master
^~~~
C:\Users\Welcome\AppData\Local\Temp\Rar$DIa0.343\MakerBotwPS2\diffirentialdrive.ino: At global scope:
diffirentialdrive:17:6: error: redefinition of 'PS2X ps2x'
PS2X ps2x; // create PS2 Controller Class
^~~~
In file included from C:\Users\Welcome\AppData\Local\Temp\Rar$DIa0.343\MakerBotwPS2\MakerBotwPS2.ino:2:0:
C:\Users\Welcome\AppData\Local\Temp\Rar$DIa0.343\MakerBotwPS2\PS2_controller.h:4:6: note: 'PS2X ps2x' previously declared here
PS2X ps2x; // create PS2 Controller Class
^~~~
diffirentialdrive:22:5: error: redefinition of 'int error'
int error = 0;
^~~~~
C:\Users\Welcome\AppData\Local\Temp\Rar$DIa0.343\MakerBotwPS2\Dpad.ino:22:5: note: 'int error' previously defined here
int error = 0;
^~~~~
diffirentialdrive:23:6: error: redefinition of 'byte type'
byte type = 0;
^~~~
C:\Users\Welcome\AppData\Local\Temp\Rar$DIa0.343\MakerBotwPS2\Dpad.ino:23:6: note: 'byte type' previously defined here
byte type = 0;
^~~~
diffirentialdrive:24:6: error: redefinition of 'byte vibrate'
byte vibrate = 0;
^~~~~~~
C:\Users\Welcome\AppData\Local\Temp\Rar$DIa0.343\MakerBotwPS2\Dpad.ino:24:6: note: 'byte vibrate' previously defined here
byte vibrate = 0;
^~~~~~~
C:\Users\Welcome\AppData\Local\Temp\Rar$DIa0.343\MakerBotwPS2\diffirentialdrive.ino: In function 'void setup()':
diffirentialdrive:26:6: error: redefinition of 'void setup()'
void setup(){
^~~~~
C:\Users\Welcome\AppData\Local\Temp\Rar$DIa0.343\MakerBotwPS2\MakerBotwPS2.ino:4:6: note: 'void setup()' previously defined here
void setup()
^~~~~
C:\Users\Welcome\AppData\Local\Temp\Rar$DIa0.343\MakerBotwPS2\diffirentialdrive.ino: In function 'void loop()':
diffirentialdrive:75:6: error: redefinition of 'void loop()'
void loop(){
^~~~
C:\Users\Welcome\AppData\Local\Temp\Rar$DIa0.343\MakerBotwPS2\MakerBotwPS2.ino:12:6: note: 'void loop()' previously defined here
void loop()
^~~~
exit status 1
redefinition of 'PS2X ps2x'
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.