Category PS4 CFW and Hacks       Thread starter PSXHAX       Start date Sep 23, 2019 at 8:00 PM       2,690       2            
We've seen Controlling a DJI Tello Drone, Controlling DeepRacer Race Cars, Controlling a Simple Wireless Rover and most recently Controlling NAO Robots with the PlayStation 4 DualShock 4 controller and alexoliveira21 has now shared a PS4ToPi DS4 to Pi Python Script on Github for use with Adafruit Industries programmable devices by scene developers. šŸŽ®

Download: ps4ToPi-master.zip / GIT

Below is the PS4ToPi script from ps4Controller.py:
Code:
import pygame
from adafruit_servokit import ServoKit

#initializes servos
kit = ServoKit(channels = 16)
steering = kit.servo[0]
motor = kit.servo[15]
steering.angle = 90
motor.angle = 90

#initializes pygame
pygame.init()

#creates a controller object
controller = pygame.joystick.Joystick(0)

#initializes the controller
controller.init()

def scale_servo(x):

        # used to scale -1,1 to 0,180
        y = round((30-70)*x+1/1+1+70,2)

        return y

try:
    while True:
        events = pygame.event.get()
        for event in events:
            angle = scale_servo(controller.get_axis(0))
            steering.angle = angle
            print("Angle: {}".format(angle))
            if event.type == pygame.JOYBUTTONDOWN:
                if controller.get_button(0):
                    print("X Pressed")
                elif controller.get_button(1):
                    print("Circle Pressed")
                elif controller.get_button(2):
                    print("Triangle Pressed")
                elif controller.get_button(3):
                    print("Square Pressed")
                elif controller.get_button(4):
                    print("L1 Pressed")
                elif controller.get_button(5):
                    print("R1 Pressed")
                elif controller.get_button(6):
                    print("L2 Pressed")
                elif controller.get_button(7):
                    print("R2 Pressed")
                elif controller.get_button(8):
                    print("SHARE Pressed")
                elif controller.get_button(9):
                    print("OPTIONS Pressed")
                elif controller.get_button(10):
                    print("Power Button Pressed")
                elif controller.get_button(11):
                    print("Left Analog Pressed")
                elif controller.get_button(12):
                    print("Right Analog Pressed")

            elif event.type == pygame.JOYBUTTONUP:
                print("Button Released")

except KeyboardInterrupt:
    print("EXITING NOW")
    controller.quit()
PS4ToPi PS4 DualShock 4 Controller to Pi Python Script by Alexoliveira21.jpg
 

Comments

Recent Articles
XNA RPKGMAN: XNA Remote Package Manager by Cypheron
Hey everyone, following PS4 PKG Sender v1.03 I have created XNA RPKGMAN: XNA Remote Package Manager which is a fully dynamic, lightweight package manager that only requires NodeJS/NPM and runs on...
Bad_Hoist PS4 Toolchain Porting Guide for Unsupported Firmware by Sleirsgoevy
Proceeding his PS4 ROP 8CC Port, Bad_Hoist 6.72 PS4 Webkit Exploit Port and preliminary Checklist to Port the Toolchain, today PlayStation 4 developer sleirsgoevy updated his Github repository...
PS4GDB Ring 0: GDB Stub to Debug PS4 Kernel by M0rph3us1987
Last month he shared a GDB Stub PS4 Port to Debug Userland Apps, and today PlayStation 4 developer m0rph3us1987 returns with a gdbstub_ring0.bin payload which is a PS4GDB Ring 0 GDB Stub for PS4...
Sony Announces DualShock 4 (DS4) Controller Colors Are Returning
We've seen Translucent Crystal, Midnight Blue & Steel Black, Berry Blue, Sunset Orange, Blue Camo & Copper, Alpine Green and Electric Purple, Red Camouflage, Titanium Blue & Rose Gold DualShock 4...
Top