Simple test¶
Ensure your device works with this simple test.
1# SPDX-FileCopyrightText: 2021 Kevin Matocha
2#
3# SPDX-License-Identifier: MIT
4#############################
5"""
6This is a basic demonstration of a Dial widget.
7"""
8
9import time
10import board
11import displayio
12import terminalio
13from displayio_dial import Dial
14
15# Fonts used for the Dial tick labels
16tick_font = terminalio.FONT
17
18display = board.DISPLAY # create the display on the PyPortal or Clue (for example)
19# otherwise change this to setup the display
20# for display chip driver and pinout you have (e.g. ILI9341)
21
22
23# Define the minimum and maximum values for the dial
24minimum_value = 0
25maximum_value = 100
26
27# Create a Dial widget
28my_dial = Dial(
29 x=20, # set x-position of the dial inside of my_group
30 y=20, # set y-position of the dial inside of my_group
31 width=180, # requested width of the dial
32 height=180, # requested height of the dial
33 padding=25, # add 25 pixels around the dial to make room for labels
34 start_angle=-120, # left angle position at -120 degrees
35 sweep_angle=240, # total sweep angle of 240 degrees
36 min_value=minimum_value, # set the minimum value shown on the dial
37 max_value=maximum_value, # set the maximum value shown on the dial
38 tick_label_font=tick_font, # the font used for the tick labels
39 tick_label_scale=2.0, # the scale factor for the tick label font
40)
41
42my_group = displayio.Group()
43my_group.append(my_dial)
44
45display.show(my_group) # add high level Group to the display
46
47step_size = 1
48
49while True:
50
51 # run the dial from minimum to maximum
52 for this_value in range(minimum_value, maximum_value + 1, step_size):
53 my_dial.value = this_value
54 display.refresh() # force the display to refresh
55 time.sleep(0.5)
56
57 # run the dial from maximum to minimum
58 for this_value in range(maximum_value, minimum_value - 1, -step_size):
59 my_dial.value = this_value
60 display.refresh() # force the display to refresh
61 time.sleep(0.5)