Simple test¶
Ensure your device works with this simple test.
1# SPDX-FileCopyrightText: 2021 GaryZ, Alec Delaney
2# SPDX-FileCopyrightText: Copyright (c) 2022 Alec Delaney for CircuitPython Organization
3#
4# SPDX-License-Identifier: Unlicense
5#############################
6"""
7Use the random fluctuation effect for the Dial.
8"""
9
10import board
11import displayio
12import terminalio
13from displayio_dial import Dial
14from displayio_effects import fluctuation_effect
15
16# Fonts used for the Dial tick labels
17tick_font = terminalio.FONT
18
19display = board.DISPLAY # create the display on the PyPortal or Clue (for example)
20# otherwise change this to setup the display
21# for display chip driver and pinout you have (e.g. ILI9341)
22
23
24# Define the minimum and maximum values for the dial
25minimum_value = 0
26maximum_value = 100
27
28# Hook in the throttle effect for the Dial widget
29fluctuation_effect.hook_fluctuation_effect(Dial, "value")
30
31# Create a Dial widget
32my_dial = Dial(
33 x=20, # set x-position of the dial inside of my_group
34 y=20, # set y-position of the dial inside of my_group
35 width=180, # requested width of the dial
36 height=180, # requested height of the dial
37 padding=25, # add 25 pixels around the dial to make room for labels
38 start_angle=-120, # left angle position at -120 degrees
39 sweep_angle=240, # total sweep angle of 240 degrees
40 min_value=minimum_value, # set the minimum value shown on the dial
41 max_value=maximum_value, # set the maximum value shown on the dial
42 tick_label_font=tick_font, # the font used for the tick labels
43 tick_label_scale=2.0, # the scale factor for the tick label font
44)
45
46
47my_group = displayio.Group()
48my_group.append(my_dial)
49
50display.show(my_group) # add high level Group to the display
51
52# Set the dial to the value before turning on the fluctuation effect
53my_dial.value = 50
54
55my_dial.fluctuation_amplitude = 5 # Fluctuate at most "5" in either direction
56my_dial.fluctuation_move_rate = 0.01 # Fluctuate at "0.01" per throttle_update()
57
58while True:
59
60 my_dial.update_fluctuation()