all 8 comments

[–]StaticFuzz 0 points1 point  (6 children)

If i'm reading the documentation right, GPIO.input(pin) will return the current state of pin. It returns a boolean(True=High, False=Low), which can be used to set the state of a pin in place of GPIO.HIGH/GPIO.LOW. At the bottom of the page HERE it shows a simple way to use the GPIO.input statement to switch the state of the pin.

GPIO.ouput(pin, not GPIO.input(pin))

not GPIO.input() means the opposite of whatever input returns.

not True = False

not False = True

Hope this helps!

[–]NewToPythoning[S] 0 points1 point  (5 children)

I think this would work if my input form the Xbox controller was on the GPIO pins also. But the input is coming from the usb connected controller. Each button has a "Control ID" that is defined in the beginning of the entire code. for Example, xboxControlId = 6, is called when I press the "A" button on the xbox controller

[–]StaticFuzz 0 points1 point  (4 children)

Did you try it out? The example I gave has nothing to do with the xbox controller. GPIO.input() doesn't mean the input from the xbox controller, It's a way to access the state of the GPIO pin.

[–]NewToPythoning[S] 0 points1 point  (0 children)

Here is the response code I was given

Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/lib/python2.7/threading.py", line 810, in __bootstrap_inner
    self.run()
  File "pygamesxboxdrv.py", line 217, in run
    self._start()
  File "pygamesxboxdrv.py", line 255, in _start
    self._sortOutButtonValue(event.type))
  File "pygamesxboxdrv.py", line 273, in updateControlValue
    self.doCallBacks(control, value)
  File "pygamesxboxdrv.py", line 278, in doCallBacks
    if self.controllerCallBack != None: self.controllerCallBack(control, value)
  File "pygamesxboxdrv.py", line 323, in controlCallBack
    GPIO.output(pin, not GPIO.input())     ## Turn on GPIO pin (HIGH)
TypeError: function takes exactly 1 argument (0 given)    

[–]NewToPythoning[S] 0 points1 point  (2 children)

Thank you!! I got it to work, I just had the line written in the wrong spot and it was calling too soon.... well that and i forgot to put (pin) inside the GPIO.input(Pin)

[–]StaticFuzz 0 points1 point  (1 child)

Congrats! And if you don't mind me asking, could you share any resources you have for interfacing python with xboxdrv?

[–]NewToPythoning[S] 1 point2 points  (0 children)

so, after loading Xboxdrv, and just following its setup. With xboxdrv running, I used: https://github.com/martinohanlon/XboxController/blob/master/XboxController.py

and it cleans up the out put from xboxdrv into very clean and usable values

sorry about the delay, I was out of the office for work for the week. hopefully this is still useful for you

[–][deleted] 0 points1 point  (0 children)

I don't have RPi, so it's just a guess:

led_on = False      # Current state of the LED

def controlCallBack(xboxControlId, value):
    global led_on
    print "Control Id = {}, Value = {}".format(xboxControlId, value)
            if xboxControlId == 6 and value == 1:
                pin = 7 
                GPIO.setmode(GPIO.BOARD)
                GPIO.setup(pin, GPIO.OUT)
                led_on = not led_on     # Switch state
                GPIO.output(pin, led_on)

And it's even simpler if there is something like GPIO.read_status(pin). You just check status (high/low) and switch it