33the PyBadge. Feel free to customize it to your heart's content.
44"""
55
6- import board
76import time
7+ from math import sqrt , cos , sin , radians
8+ import board
89from micropython import const
910import displayio
1011import digitalio
11- from math import sqrt , cos , sin , radians
1212import neopixel
1313from gamepadshift import GamePadShift
1414from adafruit_display_shapes .rect import Rect
@@ -130,22 +130,6 @@ def rotate(degrees):
130130for x in range (0 , NEOPIXEL_COUNT ):
131131 pixels .append (x * 360 // NEOPIXEL_COUNT )
132132
133- # Respond to the buttons
134- def check_buttons (buttons ):
135- global direction , speed , brightness
136- if (buttons & BUTTON_RIGHT ) > 0 :
137- direction = - 1
138- elif (buttons & BUTTON_LEFT ) > 0 :
139- direction = 1
140- elif (buttons & BUTTON_UP ) > 0 and speed < 10 :
141- speed += 1
142- elif (buttons & BUTTON_DOWN ) > 0 and speed > 1 :
143- speed -= 1
144- elif (buttons & BUTTON_A ) > 0 and brightness < 0.5 :
145- brightness += 0.025
146- elif (buttons & BUTTON_B ) > 0 and brightness > 0.025 :
147- brightness -= 0.025
148-
149133# Main Loop
150134current_buttons = pad .get_pressed ()
151135last_read = 0
@@ -165,5 +149,17 @@ def check_buttons(buttons):
165149 buttons = pad .get_pressed ()
166150 last_read = time .monotonic ()
167151 if current_buttons != buttons :
168- check_buttons (buttons )
152+ # Respond to the buttons
153+ if (buttons & BUTTON_RIGHT ) > 0 :
154+ direction = - 1
155+ elif (buttons & BUTTON_LEFT ) > 0 :
156+ direction = 1
157+ elif (buttons & BUTTON_UP ) > 0 and speed < 10 :
158+ speed += 1
159+ elif (buttons & BUTTON_DOWN ) > 0 and speed > 1 :
160+ speed -= 1
161+ elif (buttons & BUTTON_A ) > 0 and brightness < 0.5 :
162+ brightness += 0.025
163+ elif (buttons & BUTTON_B ) > 0 and brightness > 0.025 :
164+ brightness -= 0.025
169165 current_buttons = buttons
0 commit comments