Skip to content

Commit c4197e2

Browse files
committed
linted
1 parent a9db0be commit c4197e2

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

Nunchuck_Laser/code.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,22 @@
2626

2727
nc = adafruit_nunchuk.Nunchuk(i2c)
2828

29+
# Pre-calculate the angles
30+
min_yaw_angle = YAW_RANGE / 2
31+
max_yaw_angle = 180 - (YAW_RANGE / 2)
32+
min_pitch_angle = PITCH_OFFSET + (PITCH_RANGE / 2)
33+
max_pitch_angle = PITCH_OFFSET + 180 - (PITCH_RANGE / 2)
34+
2935
while True:
3036
x, y = nc.joystick
31-
servo_yaw.angle = simpleio.map_range(255 - x, 0, 255, (YAW_RANGE / 2), 180 - (YAW_RANGE / 2))
32-
servo_pitch.angle = simpleio.map_range(y, 0, 255, PITCH_OFFSET + (PITCH_RANGE / 2), PITCH_OFFSET + 180 - (PITCH_RANGE / 2))
37+
servo_yaw.angle = simpleio.map_range(255 - x, 0, 255, min_yaw_angle, max_yaw_angle)
38+
servo_pitch.angle = simpleio.map_range(y, 0, 255, min_pitch_angle, max_pitch_angle)
3339
ax = nc.acceleration[0]
3440

3541
if nc.buttons.Z: # Z-Button sets laser to full brightness
3642
laser.duty_cycle = 0xFFFF
37-
elif nc.buttons.C: # C-Button sets laser to brightness depending on the roll position of your hand
43+
elif nc.buttons.C: # C-Button sets laser brightness depending on the roll position of your hand
3844
laser.duty_cycle = int(simpleio.map_range(ax, 240, 750, 0, 0xFFFF))
3945
else: # No button pressed sets laser to off
4046
laser.duty_cycle = 0
41-
time.sleep(0.01)
47+
time.sleep(0.01)

0 commit comments

Comments
 (0)