0

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.

Chris Trudeau
  • 1,427
  • 3
  • 16
  • 20
Tigrejor
  • 1
  • 5

2 Answers2

0

Looks like to are trying to add items to a list. Make use of append().

Documentation: list.append(x) Add an item to the end of the list. Equivalent to a[len(a):] = [x].

Example of append vs extend for future use: append vs. extend

Community
  • 1
  • 1
Matt
  • 115
  • 12
0

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.

Tigrejor
  • 1
  • 5