Category PS4 CFW and Hacks       Thread starter PSXHAX       Start date Sep 23, 2019 at 8:00 PM       1,974       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
New PlayStation VR (PS VR) Headset Rumored to Arrive in 2020
We've seen PSVR2 Concepts, next-gen PS VR2 Patents, Sony's Augmented Reality Wireless Headset and based on the latest rumors a new PlayStation VR (PS VR) headset may be coming to PlayStation...
Call of Duty: Advanced Warfare PS4 Mod Menu 1.23 is Now Available
Earlier this week we saw some GTA V PS4 Mod Menu 2020 Demos, and today PlayStation 4 scene developer @CustomHooker shared via Twitter a Call of Duty: Advanced Warfare PS4 Mod Menu 1.23 with help...
PlayStation Store's Totally Digital Sale Live with Savings on PSN Games
Get set to awaken a mysterious power within to save the world in Indivisible, make a daring escape with a little help from a friend in A Way Out or fight your way through the perfect run in the...
PlayStation 5 User Interface (PS5 UI) Rumored Image Leak Surfaces
An image that is rumored to be a screenshot of the current PlayStation 5 User Interface (PS5 UI) has reportedly leaked by an Anonymous game studio employee on the popular 4Chan bulletin board. šŸ¤©...
Top