Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save AdamJHowell/7abebe0d22f231dd190ac62c2ef2b481 to your computer and use it in GitHub Desktop.
Save AdamJHowell/7abebe0d22f231dd190ac62c2ef2b481 to your computer and use it in GitHub Desktop.
#include "Ps3Controller.h"
#include "ESP32Servo.h"
Servo servoThr;
Servo servoRud;
Servo servoEle;
Servo servoAil;
int rX;
int rY;
int lX;
int lY;
int posThr = 0;
int posRud = 90;
int posEle = 90;
int posAil = 90;
void notify()
{
lX = ( Ps3.data.analog.stick.lx );
lY = ( Ps3.data.analog.stick.ly );
rX = ( Ps3.data.analog.stick.rx );
rY = ( Ps3.data.analog.stick.ry );
Serial.print( lX );
Serial.print( " " );
Serial.print( lY );
Serial.print( " " );
Serial.print( rX );
Serial.print( " " );
Serial.println( rY );
while( lY > 0 )
{
posThr = map( lY, 0, 127, 0, 180 );
servoThr.write( posThr );
}
while( abs( lX ) > 0 )
{
posRud=map( lX, -127, 127, 0, 180 );
servoRud.write( posRud );
}
while( abs( rX ) > 0 )
{
posAil = map( rX, -127, 127, 0, 180 );
servoAil.write( posAil );
}
while( abs( rY ) > 0 )
{
posEle = map( rY, -127, 127, 0, 180 );
servoEle.write( posEle );
}
}
void onConnect()
{
Serial.println( "Connected." );
}
void setup()
{
Serial.begin( 115200 );
Ps3.attach( notify );
Ps3.attachOnConnect( onConnect );
Ps3.begin( "01:02:03:04:05:06" );
Serial.println( "Ready." );
servoThr.attach( 22 );
servoRud.attach( 19 );
servoAil.attach( 23 );
servoEle.attach( 18 );
servoThr.write( posThr );
servoRud.write( posRud );
servoAil.write( posAil );
servoEle.write( posEle );
}
void loop() {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment