Skip to content

Commit 16b0d35

Browse files
committed
adding watch example
1 parent 3fc79ce commit 16b0d35

File tree

5 files changed

+83
-17
lines changed

5 files changed

+83
-17
lines changed

docs/examples.rst

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,23 @@ Ensure your device works with this simple test.
99

1010
.. image:: ../docs/dial.jpg
1111

12-
Dial Clock
12+
Two Needles
1313
------------
1414

15-
Example to use dial as a clock
15+
Example to use dial with two needles
16+
17+
.. literalinclude:: ../examples/simple_dial_two_needles.py
18+
:caption: examples/simple_dial_two_needles.py
19+
:linenos:
20+
21+
22+
Functional clock
23+
-----------------
24+
25+
Example of a functional clock
1626

1727
.. literalinclude:: ../examples/simple_dial_clock.py
1828
:caption: examples/simple_dial_clock.py
1929
:linenos:
30+
31+
.. image:: ../docs/watchwatch.gif

docs/watchwatch.gif

8.37 MB
Loading

docs/watchwatch.gif.license

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
SPDX-FileCopyrightText: Copyright (c) 2023 Neradoc
2+
3+
SPDX-License-Identifier: MIT

examples/simple_dial_clock.py

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# SPDX-FileCopyrightText: 2023 Jose David Montoya
1+
# SPDX-FileCopyrightText: 2023 Neradoc
22
#
33
# SPDX-License-Identifier: MIT
44

@@ -13,18 +13,27 @@
1313
display = board.DISPLAY
1414

1515
# Create a Dial widget
16+
width = height = int(min(display.width, display.height) * 0.9)
1617
my_dial = Dial(
17-
x=40, # set x-position
18-
y=40, # set y-position
19-
width=150, # requested width of the dial
20-
height=150, # requested height of the dial
21-
padding=12, # add 12 pixels around the dial to make room for labels
18+
x=display.width // 2 - width // 2, # set x-position
19+
y=display.height // 2 - height // 2, # set y-position
20+
width=width, # requested width of the dial
21+
height=height, # requested height of the dial
2222
tick_label_font=terminalio.FONT, # the font used for the tick labels
2323
needle_full=False,
24+
rotate_tick_labels=False,
25+
padding=24, # add 12 pixels around the dial to make room for labels
26+
tick_label_scale=2,
27+
major_tick_labels=("6", "9", "12", "3", ""),
2428
)
2529

26-
my_needle = needle(my_dial, value=30)
27-
my_needle2 = needle(my_dial, value=60)
30+
needle_hour = needle(
31+
my_dial, value=0, needle_color=0xFF0000, needle_width=5, min_value=0, max_value=12
32+
)
33+
needle_min = needle(my_dial, value=0, needle_color=0xFF8000, min_value=0, max_value=60)
34+
needle_sec = needle(
35+
my_dial, value=0, needle_color=0xFFFFFF, needle_width=2, min_value=0, max_value=60
36+
)
2837

2938
my_group = displayio.Group()
3039
my_group.append(my_dial)
@@ -34,10 +43,9 @@
3443

3544
step_size = 1
3645

37-
for this_value in range(1, 100 + 1, step_size):
38-
my_needle.value = this_value
39-
for this_other_value in range(1, 100, step_size):
40-
my_needle2.value = this_other_value
41-
display.refresh()
42-
display.refresh() # force the display to refresh
43-
time.sleep(0.5)
46+
while True:
47+
now = time.localtime()
48+
needle_hour.value = (now.tm_hour + 6) % 12
49+
needle_min.value = (now.tm_min + 30) % 60
50+
needle_sec.value = (now.tm_sec + 30) % 60
51+
display.refresh()
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# SPDX-FileCopyrightText: 2023 Jose David Montoya
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
import time
6+
import board
7+
import displayio
8+
import terminalio
9+
from circuitpython_simple_dial.simple_dial import Dial
10+
from circuitpython_simple_dial.dial_needle import needle
11+
12+
13+
display = board.DISPLAY
14+
15+
# Create a Dial widget
16+
my_dial = Dial(
17+
x=40, # set x-position
18+
y=40, # set y-position
19+
width=150, # requested width of the dial
20+
height=150, # requested height of the dial
21+
padding=12, # add 12 pixels around the dial to make room for labels
22+
tick_label_font=terminalio.FONT, # the font used for the tick labels
23+
needle_full=False,
24+
)
25+
26+
my_needle = needle(my_dial, value=30)
27+
my_needle2 = needle(my_dial, value=60)
28+
29+
my_group = displayio.Group()
30+
my_group.append(my_dial)
31+
32+
33+
display.show(my_group) # add high level Group to the display
34+
35+
step_size = 1
36+
37+
for this_value in range(1, 100 + 1, step_size):
38+
my_needle.value = this_value
39+
for this_other_value in range(1, 100, step_size):
40+
my_needle2.value = this_other_value
41+
display.refresh()
42+
display.refresh() # force the display to refresh
43+
time.sleep(0.5)

0 commit comments

Comments
 (0)