-
Notifications
You must be signed in to change notification settings - Fork 0
/
my_input.py
66 lines (56 loc) · 1.71 KB
/
my_input.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
from machine import ADC, Pin
class Input():
def __init__(self):
self.xAxis = ADC(Pin(28))
self.yAxis = ADC(Pin(29))
self.buttonB = Pin(5,Pin.IN, Pin.PULL_UP) #B
self.buttonA = Pin(6,Pin.IN, Pin.PULL_UP) #A
self.buttonStart = Pin(7,Pin.IN, Pin.PULL_UP) #A
self.buttonSelect = Pin(8,Pin.IN, Pin.PULL_UP) #A
def A(self):
if self.buttonA.value() == 0:
return True
else:
return False
def B(self):
if self.buttonB.value() == 0:
return True
else:
return False
def Start(self):
if self.buttonStart.value() == 0:
return True
else:
return False
def Select(self):
if self.buttonSelect.value() == 0:
return True
else:
return False
def x(self, down=20000, up=50000):
_temp = self.yAxis.read_u16()
if(_temp<down):
return -1
elif(_temp>up):
return 1
else:
return 0
def y(self, down=20000, up=50000):
_temp = self.xAxis.read_u16()
if(_temp<down):
return -1
elif(_temp>up):
return 1
else:
return 0
def x_raw(self):
return self.yAxis.read_u16()
def y_raw(self):
return self.xAxis.read_u16()
def test(self):
import time
while True:
print(f"x:{self.x()} y:{self.y()} x_raw:{self.x_raw()} y_raw:{self.y_raw()} A:{self.A()} B:{self.B()} Start:{self.Start()} Select:{self.Select()}")
if self.Start() and self.Select():
return
time.sleep_ms(50)