-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontroller.py
More file actions
48 lines (33 loc) · 1.01 KB
/
controller.py
File metadata and controls
48 lines (33 loc) · 1.01 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/python3
# Python file for detecting Joystick and Button Input.
import time
# Import GPIO (digital) and MCP3008 (analog) library.
import Adafruit_MCP3008
import Adafruit_GPIO as GPIO
gpio = GPIO.get_platform_gpio()
adapter = GPIO.RPiGPIOAdapter(gpio)
adapter.setup(2, GPIO.IN)
gpio.setup.assert_called_with(2, gpio.IN, pull_up_down=gpio.PUD_OFF)
print("Starting...")
gpio = GPIO.get_platform_gpio()
print("Starting 2...")
# adapter = GPIO.RPiGPIOAdapter(gpio)
# print("Starting 3...")
# adapter.setup(2, GPIO.IN)
gpio.setup(2, GPIO.IN)
# print("Starting 4...")
#gpio.setup.assert_called_with(2, gpio.IN, pull_up_down=gpio.PUD_OFF)
print("Starting 5...")
# Software SPI configuration:
CLK = 11
MISO = 9 # DOUT
MOSI = 10 # DIN
CS = 8
mcp = Adafruit_MCP3008.MCP3008(clk=CLK, cs=CS, miso=MISO, mosi=MOSI)
# Main program loop.
while True:
# Detect X Axis
jsx = mcp.read_adc(0)
# Detect Y Axis
jsy = mcp.read_adc(1)
print('X: ' + str(jsx) + ', Y: ' + str(jsy) + ', Z: ' + str(gpio.input(2)))