Search code examples
python-3.4raspberry-pi2gpioledgamepad

Error with Python 3 in RPi


First, sorry if I have a bad English or if anything is wrong, this is my first "post".
I'm trying to use a USB gamepad to turn an LED on and off with gpiozero.
I have an error while trying to execute the program:

import sys
from gpiozero import LED
led = LED(17)
pipe = open('/dev/input/js0', 'rb')
msg = []
while 1:
    for char in pipe.read(1):
        msg += [ord(char)]
            if len(msg) == 8:
                if msg[6] == 1:
                    if msg[4] == 1:
                        print ('button', msg[7], 'down')
                        led.on()
                    else:
                        print ('button', msg[7], 'up')
                        led.off()
                msg = []

Error: File "script.py", line 13, in <module>   msg += [ord(char)] TypeError: ord() expected string of length 1, but int found

What can I do to solve this?
Thanks.


Solution

  • In the end I didn't get it to work with the version I was using, I just used a different python version instead.

    Thanks for the help.