-
Notifications
You must be signed in to change notification settings - Fork 0
/
controller.py
42 lines (37 loc) · 1.07 KB
/
controller.py
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
import RPi.GPIO as GP
from threading import Thread
import requests
GP.setmode(GP.BOARD)
GP.cleanup()
GP.setup(31, GP.IN)
GP.setup(32, GP.IN)
GP.setup(36, GP.OUT)
GP.output(36, GP.HIGH)
def joystick_loop():
x = 0
y = 0
#counter = 0
while True:
#counter += 1
#print("***", counter)
if not GP.input(31):
#print("x++")
x += 1
elif not GP.input(32):
y += 1
else:
if x > 10 ** 5:
#print("down")
requests.post("http://5.253.27.186:5000/move/1/right")
elif x > 10 ** 3:
#print("up")
requests.post("http://5.253.27.186:5000/move/1/left")
if y > 10 ** 5:
#print("left")# --> up
requests.post("http://5.253.27.186:5000/move/1/up")
elif y > 10 ** 3:
#print("right") #--> down
requests.post("http://5.253.27.186:5000/move/1/down")
x, y = 0, 0
def start_controller():
Thread(target = joystick_loop).start()