Skip to content

Commit 76e8ebb

Browse files
committed
Add simple example file
1 parent 1afe4ab commit 76e8ebb

File tree

1 file changed

+59
-1
lines changed

1 file changed

+59
-1
lines changed
Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,62 @@
1-
# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries
1+
# SPDX-FileCopyrightText: 2021 Alec Delaney
22
# SPDX-FileCopyrightText: Copyright (c) 2022 Alec Delaney for CircuitPython Organization
33
#
44
# SPDX-License-Identifier: Unlicense
5+
#############################
6+
"""
7+
Use the random throttle 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 throttle_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+
throttle_effect.hook_throttle_effect(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+
48+
my_group = displayio.Group()
49+
my_group.append(my_dial)
50+
51+
display.show(my_group) # add high level Group to the display
52+
53+
# Set the dial to the value before turning on the throttle effect
54+
my_dial.value = 50
55+
56+
my_dial.throttle_effect = 5 # Fluctuate at most "5" in either direction
57+
my_dial.throttle_effect_move_rate = 0.1 # Fluctuate at "0.1" per throttle_update()
58+
59+
while True:
60+
61+
my_dial.throttle_update()
62+
display.refresh()

0 commit comments

Comments
 (0)