forked from IRL-CT/Interactive-Lab-Hub
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjoystick_test.py
More file actions
34 lines (25 loc) · 748 Bytes
/
Copy pathjoystick_test.py
File metadata and controls
34 lines (25 loc) · 748 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
from __future__ import print_function
import qwiic_joystick
import time
import sys
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)
if __name__ == '__main__':
try:
runExample()
except (KeyboardInterrupt, SystemExit) as exErr:
print("\nEnding Example 1")
sys.exit(0)