40
40
BUTTON_Y = const (1 << 9 )
41
41
BUTTON_X = const (1 << 10 )
42
42
BUTTON_SELECT = const (1 << 14 )
43
- # BUTTON_MASK = const((1 << BUTTON_A) | (1 << BUTTON_B) | (1 << BUTTON_Y) | (1 << BUTTON_X) |
44
- # (1 << BUTTON_SELECT))
45
43
46
44
47
45
class JoyFeatherWing :
@@ -70,10 +68,10 @@ def button_a(self):
70
68
from adafruit_featherwing import joy_featherwing
71
69
import time
72
70
73
- WING = joy_featherwing.JoyFeatherWing()
71
+ wing = joy_featherwing.JoyFeatherWing()
74
72
75
73
while True:
76
- if WING .button_a:
74
+ if wing .button_a:
77
75
print("Button A pressed!")
78
76
79
77
"""
@@ -93,10 +91,10 @@ def button_b(self):
93
91
from adafruit_featherwing import joy_featherwing
94
92
import time
95
93
96
- WING = joy_featherwing.JoyFeatherWing()
94
+ wing = joy_featherwing.JoyFeatherWing()
97
95
98
96
while True:
99
- if WING .button_b:
97
+ if wing .button_b:
100
98
print("Button B pressed!")
101
99
102
100
"""
@@ -116,10 +114,10 @@ def button_x(self):
116
114
from adafruit_featherwing import joy_featherwing
117
115
import time
118
116
119
- WING = joy_featherwing.JoyFeatherWing()
117
+ wing = joy_featherwing.JoyFeatherWing()
120
118
121
119
while True:
122
- if WING .button_x:
120
+ if wing .button_x:
123
121
print("Button X pressed!")
124
122
125
123
"""
@@ -139,10 +137,10 @@ def button_y(self):
139
137
from adafruit_featherwing import joy_featherwing
140
138
import time
141
139
142
- WING = joy_featherwing.JoyFeatherWing()
140
+ wing = joy_featherwing.JoyFeatherWing()
143
141
144
142
while True:
145
- if WING .button_y:
143
+ if wing .button_y:
146
144
print("Button Y pressed!")
147
145
148
146
"""
@@ -162,10 +160,10 @@ def button_select(self):
162
160
from adafruit_featherwing import joy_featherwing
163
161
import time
164
162
165
- WING = joy_featherwing.JoyFeatherWing()
163
+ wing = joy_featherwing.JoyFeatherWing()
166
164
167
165
while True:
168
- if WING .button_select:
166
+ if wing .button_select:
169
167
print("Button SELECT pressed!")
170
168
171
169
"""
@@ -178,12 +176,7 @@ def _check_button(self, button):
178
176
179
177
@property
180
178
def joystick_offset (self ):
181
- """Returns the joystick offset, set by the `joystick_offset.setter`."""
182
- return self ._joystick_offset
183
-
184
- @joystick_offset .setter
185
- def joystick_offset (self , offset ):
186
- """Allows for setting explicit numbers to effectively zero the joystick.
179
+ """Offset used to correctly report (0, 0) when the joystick is centered.
187
180
188
181
.. image :: /_static/joy_featherwing/joy_featherwing_joystick.jpg
189
182
:alt: Joy FeatherWing Joystick
@@ -202,20 +195,24 @@ def joystick_offset(self, offset):
202
195
from adafruit_featherwing import joy_featherwing
203
196
import time
204
197
205
- WING = joy_featherwing.JoyFeatherWing()
206
- LAST_X = 0
207
- LAST_Y = 0
198
+ wing = joy_featherwing.JoyFeatherWing()
199
+ last_x = 0
200
+ last_y = 0
208
201
209
202
while True:
210
203
wing.joystick_offset = (-4, 0)
211
- x, y = WING .joystick
212
- if (abs(x - LAST_X ) > 3) or (abs(y - LAST_Y ) > 3):
213
- LAST_X = x
214
- LAST_Y = y
204
+ x, y = wing .joystick
205
+ if (abs(x - last_x ) > 3) or (abs(y - last_y ) > 3):
206
+ last_x = x
207
+ last_y = y
215
208
print(x, y)
216
209
time.sleep(0.01)
217
210
218
211
"""
212
+ return self ._joystick_offset
213
+
214
+ @joystick_offset .setter
215
+ def joystick_offset (self , offset ):
219
216
self ._joystick_offset = offset
220
217
221
218
def zero_joystick (self ):
@@ -234,16 +231,16 @@ def zero_joystick(self):
234
231
from adafruit_featherwing import joy_featherwing
235
232
import time
236
233
237
- WING = joy_featherwing.JoyFeatherWing()
238
- LAST_X = 0
239
- LAST_Y = 0
240
- WING .zero_joystick()
234
+ wing = joy_featherwing.JoyFeatherWing()
235
+ last_x = 0
236
+ last_y = 0
237
+ wing .zero_joystick()
241
238
242
239
while True:
243
- x, y = WING .joystick
244
- if (abs(x - LAST_X ) > 3) or (abs(y - LAST_Y ) > 3):
245
- LAST_X = x
246
- LAST_Y = y
240
+ x, y = wing .joystick
241
+ if (abs(x - last_x ) > 3) or (abs(y - last_y ) > 3):
242
+ last_x = x
243
+ last_y = y
247
244
print(x, y)
248
245
time.sleep(0.01)
249
246
@@ -266,16 +263,16 @@ def joystick(self):
266
263
from adafruit_featherwing import joy_featherwing
267
264
import time
268
265
269
- WING = joy_featherwing.JoyFeatherWing()
270
- LAST_X = 0
271
- LAST_Y = 0
272
- WING .zero_joystick()
266
+ wing = joy_featherwing.JoyFeatherWing()
267
+ last_x = 0
268
+ last_y = 0
269
+ wing .zero_joystick()
273
270
274
271
while True:
275
- x, y = WING .joystick
276
- if (abs(x - LAST_X ) > 3) or (abs(y - LAST_Y ) > 3):
277
- LAST_X = x
278
- LAST_Y = y
272
+ x, y = wing .joystick
273
+ if (abs(x - last_x ) > 3) or (abs(y - last_y ) > 3):
274
+ last_x = x
275
+ last_y = y
279
276
print(x, y)
280
277
time.sleep(0.01)
281
278
"""
0 commit comments