Skip to content

Commit 37e93d8

Browse files
committed
lint
1 parent c0d75b8 commit 37e93d8

File tree

1 file changed

+129
-130
lines changed

1 file changed

+129
-130
lines changed

Toddler_Timer/code.py

Lines changed: 129 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -1,130 +1,129 @@
1-
# SPDX-FileCopyrightText: 2025 Liz Clark for Adafruit Industries
2-
#
3-
# SPDX-License-Identifier: MIT
4-
5-
import time
6-
import board
7-
import displayio
8-
import neopixel
9-
import digitalio
10-
from adafruit_seesaw import seesaw, rotaryio, digitalio
11-
from adafruit_bitmap_font import bitmap_font
12-
from adafruit_display_text import label
13-
import adafruit_displayio_ssd1306
14-
import simpleio
15-
from adafruit_ticks import ticks_ms, ticks_add, ticks_diff
16-
from rainbowio import colorwheel
17-
18-
COLOR = (255, 150, 0) # yellow
19-
OFF = (0, 0, 0)
20-
PIXEL_PIN = board.A0
21-
NUM_PIXELS = 6
22-
timers = [6, 10, 15, 20, 25, 30] # minutes
23-
color_time = 20 # milliseconds
24-
25-
# rotary encoder
26-
i2c = board.STEMMA_I2C()
27-
seesaw = seesaw.Seesaw(i2c, addr=0x36)
28-
encoder = rotaryio.IncrementalEncoder(seesaw)
29-
pos = -encoder.position
30-
last_pos = pos
31-
seesaw.pin_mode(24, seesaw.INPUT_PULLUP)
32-
button = digitalio.DigitalIO(seesaw, 24)
33-
button_state = False
34-
35-
pixels = neopixel.NeoPixel(PIXEL_PIN, NUM_PIXELS, brightness=0.2, auto_write=False)
36-
pixels.fill(OFF)
37-
pixels.show()
38-
39-
# display setup
40-
displayio.release_displays()
41-
42-
# oled
43-
oled_reset = board.D9
44-
display_bus = displayio.I2CDisplay(i2c, device_address=0x3D, reset=oled_reset)
45-
WIDTH = 128
46-
HEIGHT = 64
47-
display = adafruit_displayio_ssd1306.SSD1306(display_bus, width=WIDTH, height=HEIGHT)
48-
49-
font = bitmap_font.load_font("/Arial-14.bdf")
50-
main_area = label.Label(font, text="6 Minutes", color=0xFFFFFF)
51-
main_area.anchor_point = (0.5, 0.0)
52-
main_area.anchored_position = (display.width / 2, display.height / 2)
53-
splash = displayio.Group()
54-
splash.append(main_area)
55-
display.root_group = splash
56-
57-
timer_index = 0
58-
timer = timers[timer_index]
59-
time_remaining = timer * 60000
60-
active_timer = False
61-
timer_clock = ticks_ms()
62-
color_clock = ticks_ms()
63-
color_value = 0
64-
last_map = 0
65-
mapped_time = 0
66-
67-
while True:
68-
if not active_timer:
69-
pos = encoder.position
70-
if pos != last_pos:
71-
if pos > last_pos:
72-
timer_index = (timer_index + 1) % 6
73-
else:
74-
timer_index = (timer_index - 1) % 6
75-
print(timer_index)
76-
main_area.text = f"{timers[timer_index]} Minutes"
77-
last_pos = pos
78-
if not button.value and not button_state:
79-
main_area.text = "START!"
80-
timer = timers[timer_index]
81-
time_remaining = timer * 60000
82-
last_map = 0
83-
timer_clock = ticks_ms()
84-
color_clock = ticks_ms()
85-
active_timer = True
86-
button_state = True
87-
if button.value and button_state:
88-
button_state = False
89-
if active_timer:
90-
if ticks_diff(ticks_ms(), timer_clock) >= 1000:
91-
time_remaining -= 1000
92-
remaining = int(time_remaining / 1000)
93-
secs_remaining = remaining % 60
94-
remaining //= 60
95-
mins_remaining = remaining % 60
96-
if time_remaining > 0:
97-
mapped_time = simpleio.map_range(
98-
time_remaining, 0, (timer * 60000), 0, NUM_PIXELS + 1
99-
)
100-
if mapped_time < 1:
101-
mapped_time = 1
102-
if int(mapped_time) != last_map:
103-
pixels.fill(OFF)
104-
last_map = int(mapped_time)
105-
main_area.text = f"{mins_remaining}:{secs_remaining:02}"
106-
else:
107-
pixels.fill(COLOR)
108-
pixels.show()
109-
time.sleep(0.5)
110-
pixels.fill(OFF)
111-
pixels.show()
112-
main_area.text = "DONE!"
113-
print(time_remaining)
114-
timer_clock = ticks_add(timer_clock, 1000)
115-
if ticks_diff(ticks_ms(), color_clock) >= color_time:
116-
color_value = (color_value + 1) % 255
117-
for i in range(int(mapped_time)):
118-
pixels[i] = colorwheel(color_value)
119-
if time_remaining > 0:
120-
pixels.show()
121-
color_clock = ticks_add(color_clock, color_time)
122-
if not button.value and not button_state:
123-
timer = timers[timer_index]
124-
pixels.fill(OFF)
125-
pixels.show()
126-
main_area.text = "STOPPED"
127-
active_timer = False
128-
button_state = True
129-
if button.value and button_state:
130-
button_state = False
1+
# SPDX-FileCopyrightText: 2025 Liz Clark for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
import time
6+
import board
7+
import displayio
8+
import neopixel
9+
import digitalio
10+
from adafruit_seesaw import seesaw, rotaryio, digitalio
11+
from adafruit_bitmap_font import bitmap_font
12+
from adafruit_display_text import label
13+
import adafruit_displayio_ssd1306
14+
import simpleio
15+
from adafruit_ticks import ticks_ms, ticks_add, ticks_diff
16+
from rainbowio import colorwheel
17+
18+
COLOR = (255, 150, 0) # yellow
19+
OFF = (0, 0, 0)
20+
PIXEL_PIN = board.A0
21+
NUM_PIXELS = 6
22+
timers = [6, 10, 15, 20, 25, 30] # minutes
23+
color_time = 20 # milliseconds
24+
25+
# rotary encoder
26+
i2c = board.STEMMA_I2C()
27+
seesaw = seesaw.Seesaw(i2c, addr=0x36)
28+
encoder = rotaryio.IncrementalEncoder(seesaw)
29+
pos = -encoder.position
30+
last_pos = pos
31+
seesaw.pin_mode(24, seesaw.INPUT_PULLUP)
32+
button = digitalio.DigitalIO(seesaw, 24)
33+
button_state = False
34+
35+
pixels = neopixel.NeoPixel(PIXEL_PIN, NUM_PIXELS, brightness=0.2, auto_write=False)
36+
pixels.fill(OFF)
37+
pixels.show()
38+
39+
# display setup
40+
displayio.release_displays()
41+
42+
# oled
43+
oled_reset = board.D9
44+
display_bus = displayio.I2CDisplay(i2c, device_address=0x3D, reset=oled_reset)
45+
WIDTH = 128
46+
HEIGHT = 64
47+
display = adafruit_displayio_ssd1306.SSD1306(display_bus, width=WIDTH, height=HEIGHT)
48+
49+
font = bitmap_font.load_font("/Arial-14.bdf")
50+
main_area = label.Label(font, text="6 Minutes", color=0xFFFFFF)
51+
main_area.anchor_point = (0.5, 0.0)
52+
main_area.anchored_position = (display.width / 2, display.height / 2)
53+
splash = displayio.Group()
54+
splash.append(main_area)
55+
display.root_group = splash
56+
57+
timer_index = 0
58+
timer = timers[timer_index]
59+
time_remaining = timer * 60000
60+
active_timer = False
61+
timer_clock = ticks_ms()
62+
color_clock = ticks_ms()
63+
color_value = 0
64+
last_map = 0
65+
mapped_time = 0
66+
67+
while True:
68+
if not active_timer:
69+
pos = encoder.position
70+
if pos != last_pos:
71+
if pos > last_pos:
72+
timer_index = (timer_index + 1) % 6
73+
else:
74+
timer_index = (timer_index - 1) % 6
75+
print(timer_index)
76+
main_area.text = f"{timers[timer_index]} Minutes"
77+
last_pos = pos
78+
if not button.value and not button_state:
79+
main_area.text = "START!"
80+
timer = timers[timer_index]
81+
time_remaining = timer * 60000
82+
last_map = 0
83+
timer_clock = ticks_ms()
84+
color_clock = ticks_ms()
85+
active_timer = True
86+
button_state = True
87+
if button.value and button_state:
88+
button_state = False
89+
if active_timer:
90+
if ticks_diff(ticks_ms(), timer_clock) >= 1000:
91+
time_remaining -= 1000
92+
remaining = int(time_remaining / 1000)
93+
secs_remaining = remaining % 60
94+
remaining //= 60
95+
mins_remaining = remaining % 60
96+
if time_remaining > 0:
97+
mapped_time = simpleio.map_range(
98+
time_remaining, 0, (timer * 60000), 0, NUM_PIXELS + 1
99+
)
100+
mapped_time = max(mapped_time, 1)
101+
if int(mapped_time) != last_map:
102+
pixels.fill(OFF)
103+
last_map = int(mapped_time)
104+
main_area.text = f"{mins_remaining}:{secs_remaining:02}"
105+
else:
106+
pixels.fill(COLOR)
107+
pixels.show()
108+
time.sleep(0.5)
109+
pixels.fill(OFF)
110+
pixels.show()
111+
main_area.text = "DONE!"
112+
print(time_remaining)
113+
timer_clock = ticks_add(timer_clock, 1000)
114+
if ticks_diff(ticks_ms(), color_clock) >= color_time:
115+
color_value = (color_value + 1) % 255
116+
for i in range(int(mapped_time)):
117+
pixels[i] = colorwheel(color_value)
118+
if time_remaining > 0:
119+
pixels.show()
120+
color_clock = ticks_add(color_clock, color_time)
121+
if not button.value and not button_state:
122+
timer = timers[timer_index]
123+
pixels.fill(OFF)
124+
pixels.show()
125+
main_area.text = "STOPPED"
126+
active_timer = False
127+
button_state = True
128+
if button.value and button_state:
129+
button_state = False

0 commit comments

Comments
 (0)