Skip to content

Instantly share code, notes, and snippets.

@nmk456
Last active December 20, 2017 13:26
Show Gist options
  • Save nmk456/990bce8bd039f59f1e6a95183b78ec1f to your computer and use it in GitHub Desktop.
Save nmk456/990bce8bd039f59f1e6a95183b78ec1f to your computer and use it in GitHub Desktop.
Control RC with Pi.
from .xbox import Joystick
import time
import Adafruit_PCA9685
"""
Dependencies:
https://github.com/adafruit/Adafruit_Python_PCA9685
https://github.com/FRC4564/Xbox
https://github.com/ynsta/steamcontroller
"""
def scale(val, src, dst):
# Scale the given value from the scale of src to the scale of dst.
return ((val - src[0]) / (src[1]-src[0])) * (dst[1]-dst[0]) + dst[0]
pwm = Adafruit_PCA9685.PCA9685()
pwm.setPWMFreq(1000)
joy = xbox.Joystick()
m_chan = 0
s_chan = 1
while True:
throttle = joy.rightTrigger() - leftTrigger()
setPWM(m_chan, 0, scale(throttle, (-1.0, 1.0), (0, 4095))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment