Skip to content

Commit 1adab7b

Browse files
committed
Add example for colorwheel effect
1 parent 5f66f81 commit 1adab7b

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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+
"""
7+
Use the random fluctuation effect for the Dial.
8+
"""
9+
10+
import time
11+
import board
12+
import displayio
13+
import terminalio
14+
from displayio_dial import Dial
15+
from displayio_effects import WidgetType, colorwheel_effect
16+
17+
# Fonts used for the Dial tick labels
18+
tick_font = terminalio.FONT
19+
20+
display = 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
26+
minimum_value = 0
27+
maximum_value = 100
28+
29+
# Hook in the throttle effect for the Dial widget
30+
colorwheel_effect.hook_colorwheel_effect(Dial, WidgetType.DIAL)
31+
32+
# Create a Dial widget
33+
my_dial = Dial(
34+
x=20, # set x-position of the dial inside of my_group
35+
y=20, # set y-position of the dial inside of my_group
36+
width=180, # requested width of the dial
37+
height=180, # requested height of the dial
38+
padding=25, # add 25 pixels around the dial to make room for labels
39+
start_angle=-120, # left angle position at -120 degrees
40+
sweep_angle=240, # total sweep angle of 240 degrees
41+
min_value=minimum_value, # set the minimum value shown on the dial
42+
max_value=maximum_value, # set the maximum value shown on the dial
43+
tick_label_font=tick_font, # the font used for the tick labels
44+
tick_label_scale=2.0, # the scale factor for the tick label font
45+
)
46+
47+
my_group = displayio.Group()
48+
my_group.append(my_dial)
49+
50+
display.show(my_group) # add high level Group to the display
51+
52+
# Set the dial to the value before turning on the fluctuation effect
53+
my_dial.value = 50
54+
55+
while True:
56+
57+
my_dial.update_colorwheel()
58+
time.sleep(0.01)

0 commit comments

Comments
 (0)