Jump to content

Making a value biger after i press the controlor button

Symbolls
Go to solution Solved by C2dan88,

This error

Quote
TypeError: on_x_press() missing 1 required positional argument: 'angle_count'

Says you are calling on_x_press() function without passing any arguments to it. 

Your function definition defines 1 argument angle_count

def on_x_press(self, angle_count):

If you dont need to pass an argument to the function then remove the argument

def on_x_press(self):

 

angle_count is a property to the MyController class. You need to use self.angle_count in your functions when you need to use it.

To increment its value by 1 you can  += operator

    def on_x_press(self):
        print("1")
        self.angle_count += 1 // increment angle_count by 1

To deincrement the value you can use -= operator

    def on_circle_press(self):
        self.angle_count -= 1

 

Hello i am working on a project and i am not good at programing and i want when i press the button on my ps4 controller the value of a variable to increse witch will add 10 degreze to the servomotro angle

thx in advance

 

i am sorry if my code is mess i am a noob when it comes to programing

 

from adafruit_servokit import ServoKit
import time
from pyPS4Controller.controller import Controller
kit = ServoKit(channels=16)
kit.servo[0].actuation_range = 180

class MyController(Controller):

    angle_count = 0


    def __init__(self, angle_count):
        self.angle_count = angle_count
        angle_count.person_count += 1  # here


    def __init__(self, **kwargs):
        Controller.__init__(self, **kwargs)

    def on_x_press(self, angle_count):
        print("1")
        angle_count + 1
        print(angle_count)
        #Angle.angle_count += 1
        #print(Angle.angle_count)
        #kit.servo[0].angle = 180

#    def on_x_release(self):


    def on_circle_press(self):
        print("2")
        #print(Angle.angle_count)
        #kit.servo[0].angle = 0

controller = MyController(interface="/dev/input/js0", connecting_using_ds4drv=False)
controller.listen(timeout=60)

 

Error:

Waiting for interface: /dev/input/js0 to become available . . .
Successfully bound to: /dev/input/js0.
Traceback (most recent call last):
  File "/home/symbolls/Desktop/Code Project RAmk2/Ver1.py", line 37, in <module>
    controller.listen(timeout=60)
  File "/home/symbolls/Desktop/Code Project RAmk2/lib/python3.6/site-packages/pyPS4Controller/controller.py", line 263, in listen
    debug=self.debug)
  File "/home/symbolls/Desktop/Code Project RAmk2/lib/python3.6/site-packages/pyPS4Controller/controller.py", line 319, in __handle_event
    self.on_x_press()
TypeError: on_x_press() missing 1 required positional argument: 'angle_count'
Exiting... 
Cleaning up pins

Process finished with exit code 1

 

Link to comment
Share on other sites

Link to post
Share on other sites

This error

Quote
TypeError: on_x_press() missing 1 required positional argument: 'angle_count'

Says you are calling on_x_press() function without passing any arguments to it. 

Your function definition defines 1 argument angle_count

def on_x_press(self, angle_count):

If you dont need to pass an argument to the function then remove the argument

def on_x_press(self):

 

angle_count is a property to the MyController class. You need to use self.angle_count in your functions when you need to use it.

To increment its value by 1 you can  += operator

    def on_x_press(self):
        print("1")
        self.angle_count += 1 // increment angle_count by 1

To deincrement the value you can use -= operator

    def on_circle_press(self):
        self.angle_count -= 1

 

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×