Skip to content

Commit 16c2dc0

Browse files
author
Alexander Wilde
committed
Make Galatic clock example responsive
1 parent 8f5a944 commit 16c2dc0

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

micropython/examples/cosmic_unicorn/clock.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,11 +158,13 @@ def sync_time():
158158

159159

160160
def adjust_utc_offset(pin):
161-
global utc_offset
161+
global utc_offset, last_second
162162
if pin == up_button:
163163
utc_offset += 1
164+
last_second = None
164165
if pin == down_button:
165166
utc_offset -= 1
167+
last_second = None
166168

167169

168170
up_button.irq(trigger=machine.Pin.IRQ_FALLING, handler=adjust_utc_offset)
@@ -214,9 +216,11 @@ def redraw_display_if_reqd():
214216
while True:
215217
if cu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_UP):
216218
cu.adjust_brightness(+0.01)
219+
last_second = None
217220

218221
if cu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_DOWN):
219222
cu.adjust_brightness(-0.01)
223+
last_second = None
220224

221225
if cu.is_pressed(CosmicUnicorn.SWITCH_A):
222226
sync_time()

micropython/examples/galactic_unicorn/clock.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,11 +159,13 @@ def sync_time():
159159

160160

161161
def adjust_utc_offset(pin):
162-
global utc_offset
162+
global utc_offset, last_second
163163
if pin == up_button:
164164
utc_offset += 1
165+
last_second = None
165166
if pin == down_button:
166167
utc_offset -= 1
168+
last_second = None
167169

168170

169171
up_button.irq(trigger=machine.Pin.IRQ_FALLING, handler=adjust_utc_offset)
@@ -215,9 +217,11 @@ def redraw_display_if_reqd():
215217
while True:
216218
if gu.is_pressed(GalacticUnicorn.SWITCH_BRIGHTNESS_UP):
217219
gu.adjust_brightness(+0.01)
220+
last_second = None
218221

219222
if gu.is_pressed(GalacticUnicorn.SWITCH_BRIGHTNESS_DOWN):
220223
gu.adjust_brightness(-0.01)
224+
last_second = None
221225

222226
if gu.is_pressed(GalacticUnicorn.SWITCH_A):
223227
sync_time()

micropython/examples/stellar_unicorn/clock.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,11 +158,13 @@ def sync_time():
158158

159159

160160
def adjust_utc_offset(pin):
161-
global utc_offset
161+
global utc_offset, last_second
162162
if pin == up_button:
163163
utc_offset += 1
164+
last_second = None
164165
if pin == down_button:
165166
utc_offset -= 1
167+
last_second = None
166168

167169

168170
up_button.irq(trigger=machine.Pin.IRQ_FALLING, handler=adjust_utc_offset)
@@ -214,9 +216,11 @@ def redraw_display_if_reqd():
214216
while True:
215217
if su.is_pressed(StellarUnicorn.SWITCH_BRIGHTNESS_UP):
216218
su.adjust_brightness(+0.01)
219+
last_second = None
217220

218221
if su.is_pressed(StellarUnicorn.SWITCH_BRIGHTNESS_DOWN):
219222
su.adjust_brightness(-0.01)
223+
last_second = None
220224

221225
if su.is_pressed(StellarUnicorn.SWITCH_A):
222226
sync_time()

0 commit comments

Comments
 (0)