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