Exemplo n.º 1
0
def runExample():

    print("\nSparkFun qwiic Joystick   Example 2\n")
    myJoystick = qwiic_joystick.QwiicJoystick()

    if myJoystick.connected == False:
        print("The Qwiic Joystick device isn't connected to the system. Please check your connection", \
         file=sys.stderr)
        return

    myJoystick.begin()

    print("Initialized. Firmware Version: %s" % myJoystick.version)

    while True:

        x = myJoystick.horizontal
        y = myJoystick.vertical
        b = myJoystick.button

        if x > 575:
            print("L")
        elif x < 450:
            print("R")

        if y > 575:
            print("U")
        elif y < 450:
            print("D")

        if b == 0:
            print("Button")

        time.sleep(.5)
Exemplo n.º 2
0
 def __init__(self):
     self.joy1 = qwiic_joystick.QwiicJoystick()
     self.horizontal1 = 0.0
     self.vertical1 = 0.0
     self.button1 = False
     self.mouse = Controller()
     self.cmd_pub = rospy.Publisher("cmd_vel", Twist, queue_size=0)
     self.timer = rospy.Time.now()
     self.mode = 1
     self.buttons = rospy.get_param('/controller/buttons')
     col = []
     for i in range(len(self.buttons['id'])):
         col.append(0)
     self.button_matrix = [[1,0,0],[0,0,0],col]
     self.button_pub = rospy.Publisher('button_matrix', Int32MultiArray, queue_size=0)
def runExample():

    print("\nSparkFun qwiic Joystick   Example 1\n")
    myJoystick = qwiic_joystick.QwiicJoystick()

    if myJoystick.connected == False:
        print("The Qwiic Joystick device isn't connected to the system. Please check your connection", \
         file=sys.stderr)
        return

    myJoystick.begin()

    print("Initialized. Firmware Version: %s" % myJoystick.version)

    while True:

        print("X: %d, Y: %d, Button: %d" % ( \
           myJoystick.horizontal, \
           myJoystick.vertical, \
           myJoystick.button))

        time.sleep(.5)
Exemplo n.º 4
0
# Move left to right keeping track of the current x position for drawing shapes.
x = 0

# Alternatively load a TTF font.  Make sure the .ttf font file is in the
# same directory as the python script!
# Some other nice fonts to try: http://www.dafont.com/bitmap.php
font = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf",
                          18)

# Turn on the backlight
backlight = digitalio.DigitalInOut(board.D22)
backlight.switch_to_output()
backlight.value = True

# Set up the joystick
joystick = qwiic_joystick.QwiicJoystick()
joystick.begin()

# Set up first button
redButton = qwiic_button.QwiicButton()
redButton.begin()

greenButton = qwiic_button.QwiicButton(0x62)
greenButton.begin()

while True:
    if greenButton.is_button_pressed():
        print('green pressed')
    if redButton.is_button_pressed():
        print('red pressed')