hcnuPcitirC
Hectopat
- Katılım
- 21 Mayıs 2022
- Mesajlar
- 780
- Çözümler
- 4
Daha fazla
- Cinsiyet
- Erkek
DualSense kontrolcüsünü arabada kullanmak istiyorum fakat yaptığım bağlantılar yanlış herhalde arabaya ESP32'yi bağlayınca DualSense bağlanmıyor. Sorun nedir?
- IN1: Gpıo 23.
- IN2: Gpıo 22.
- IN3: Gpıo 21.
- IN4: Gpıo 19.
Ena 14.
Enb 15.
Kod:#include <ps5Controller.h> //Right motor. int enableRightMotor=22; int rightMotorPin1=16; int rightMotorPin2=17; //Left motor. int enableLeftMotor=23; int leftMotorPin1=18; int leftMotorPin2=19; const int PWMFreq = 1000; /* 1 KHz */ const int PWMResolution = 8; const int rightMotorPWMSpeedChannel = 4; const int leftMotorPWMSpeedChannel = 5; void notify() { int yAxisValue =(ps5.data.analog.stick.ly); //Left stick - y axis - forward/backward car movement. int xAxisValue =(ps5.data.analog.stick.rx); //Right stick - x axis - left/right car movement. int throttle = map( yAxisValue, -127, 127, -255, 255); int steering = map( xAxisValue, -127, 127, -255, 255); int motorDirection = 1; if (throttle < 0) //Move car backward. { motorDirection = -1; } int rightMotorSpeed, leftMotorSpeed; rightMotorSpeed = abs(throttle) - steering; leftMotorSpeed = abs(throttle) + steering; rightMotorSpeed = constrain(rightMotorSpeed, 0, 255); leftMotorSpeed = constrain(leftMotorSpeed, 0, 255); rotateMotor(rightMotorSpeed * motorDirection, leftMotorSpeed * motorDirection); } void onConnect() { Serial.println("Connected!."); } void onDisConnect() { rotateMotor(0, 0); Serial.println("Disconnected!."); } void rotateMotor(int rightMotorSpeed, int leftMotorSpeed) { if (rightMotorSpeed < 0) { digitalWrite(rightMotorPin1,LOW); digitalWrite(rightMotorPin2,HIGH); } else if (rightMotorSpeed > 0) { digitalWrite(rightMotorPin1,HIGH); digitalWrite(rightMotorPin2,LOW); } else. { digitalWrite(rightMotorPin1,LOW); digitalWrite(rightMotorPin2,LOW); } if (leftMotorSpeed < 0) { digitalWrite(leftMotorPin1,LOW); digitalWrite(leftMotorPin2,HIGH); } else if (leftMotorSpeed > 0) { digitalWrite(leftMotorPin1,HIGH); digitalWrite(leftMotorPin2,LOW); } else. { digitalWrite(leftMotorPin1,LOW); digitalWrite(leftMotorPin2,LOW); } ledcWrite(rightMotorPWMSpeedChannel, abs(rightMotorSpeed)); ledcWrite(leftMotorPWMSpeedChannel, abs(leftMotorSpeed)); } void setUpPinModes() { pinMode(enableRightMotor,OUTPUT); pinMode(rightMotorPin1,OUTPUT); pinMode(rightMotorPin2,OUTPUT); pinMode(enableLeftMotor,OUTPUT); pinMode(leftMotorPin1,OUTPUT); pinMode(leftMotorPin2,OUTPUT); //Set up PWM for motor speed. ledcSetup(rightMotorPWMSpeedChannel, PWMFreq, PWMResolution); ledcSetup(leftMotorPWMSpeedChannel, PWMFreq, PWMResolution); ledcAttachPin(enableRightMotor, rightMotorPWMSpeedChannel); ledcAttachPin(enableLeftMotor, leftMotorPWMSpeedChannel); rotateMotor(0, 0); } void setup() { setUpPinModes(); Serial.begin(115200); ps5.attach(notify); ps5.attachOnConnect(onConnect); ps5.attachOnDisconnect(onDisConnect); ps5.begin("ac:36:1b:2e:ad:e5"); while (ps5.isConnected() == false) { Serial.println("PS5 controller not found"); delay(300); } Serial.println("Ready."); } void loop() { }
D