Simple test

Ensure your device works with this simple test.

examples/simple_dial_test.py
 1# SPDX-FileCopyrightText: 2023 Jose David Montoya
 2#
 3# SPDX-License-Identifier: MIT
 4
 5import time
 6import board
 7import displayio
 8import terminalio
 9from circuitpython_simple_dial.simple_dial import Dial
10from circuitpython_simple_dial.dial_needle import needle
11
12
13display = board.DISPLAY
14
15# Create a Dial widget
16my_dial = Dial(
17    x=100,  # set x-position
18    y=120,  # 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)
24
25my_needle = needle(my_dial)
26
27my_group = displayio.Group()
28my_group.append(my_dial)
29
30display.show(my_group)  # add high level Group to the display
31
32step_size = 1
33
34for this_value in range(1, 100 + 1, step_size):
35    my_needle.value = this_value
36    display.refresh()  # force the display to refresh
37time.sleep(0.5)
38
39# run the dial from maximum to minimum
40for this_value in range(100, 1 - 1, -step_size):
41    my_needle.value = this_value
42    display.refresh()  # force the display to refresh
43time.sleep(0.5)
_images/dial.jpg

Two Needles

Example to use dial with two needles

examples/simple_dial_two_needles.py
 1# SPDX-FileCopyrightText: 2023 Jose David Montoya
 2#
 3# SPDX-License-Identifier: MIT
 4
 5import time
 6import board
 7import displayio
 8import terminalio
 9from circuitpython_simple_dial.simple_dial import Dial
10from circuitpython_simple_dial.dial_needle import needle
11
12
13display = board.DISPLAY
14
15# Create a Dial widget
16my_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
26my_needle = needle(my_dial, value=30)
27my_needle2 = needle(my_dial, value=60)
28
29my_group = displayio.Group()
30my_group.append(my_dial)
31
32
33display.show(my_group)  # add high level Group to the display
34
35step_size = 1
36
37for 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
43time.sleep(0.5)

Functional clock

Example of a functional clock

examples/simple_dial_clock.py
 1# SPDX-FileCopyrightText: 2023 Neradoc
 2#
 3# SPDX-License-Identifier: MIT
 4
 5import time
 6import board
 7import displayio
 8import terminalio
 9from circuitpython_simple_dial.simple_dial import Dial
10from circuitpython_simple_dial.dial_needle import needle
11
12
13display = board.DISPLAY
14
15# Create a Dial widget
16width = height = int(min(display.width, display.height) * 0.9)
17my_dial = Dial(
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
22    tick_label_font=terminalio.FONT,  # the font used for the tick labels
23    needle_full=False,
24    padding=24,  # add 12 pixels around the dial to make room for labels
25    tick_label_scale=2,
26    major_tick_labels=(
27        "6",
28        "9",
29        "12",
30        "3",
31    ),
32    minor_tick_labels=(
33        "7",
34        "8",
35        "10",
36        "11",
37        "1",
38        "2",
39        "4",
40        "5",
41    ),
42)
43
44needle_hour = needle(
45    my_dial,
46    value=0,
47    needle_color=0xFF0000,
48    needle_width=5,
49    needle_pad=30,
50    min_value=0,
51    max_value=12,
52)
53needle_min = needle(
54    my_dial, value=0, needle_color=0xFF8000, needle_width=5, min_value=0, max_value=60
55)
56needle_sec = needle(
57    my_dial, value=0, needle_color=0xFFFFFF, needle_width=2, min_value=0, max_value=60
58)
59
60my_group = displayio.Group()
61my_group.append(my_dial)
62
63display.show(my_group)
64
65while True:
66    now = time.localtime()
67    needle_hour.value = (now.tm_hour + 7) % 12
68    needle_min.value = (now.tm_min + 30) % 60
69    needle_sec.value = (now.tm_sec + 30) % 60
70    display.refresh()
_images/watchwatch.gif