Skip to content

Commit a51a1f6

Browse files
committed
Added example provided by @FoamyGuy
1 parent f5d7ed9 commit a51a1f6

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

examples/progressbar_combined.py

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/usr/bin/env python3
2+
3+
# SPDX-FileCopyrightText: 2021 Hugo Dahl for Adafruit Industries
4+
# SPDX-License-Identifier: MIT
5+
6+
# Before you can run this example, you will need to install the
7+
# required libraries identifies in the `requirements.txt` file.
8+
# You can do so automatically by using the "pip" utility.
9+
10+
import time
11+
import board
12+
import displayio
13+
from adafruit_progressbar.horizontalprogressbar import HorizontalProgressBar
14+
from adafruit_progressbar.verticalprogressbar import VerticalProgressBar
15+
16+
# Make the display context
17+
splash = displayio.Group(max_size=10)
18+
board.DISPLAY.show(splash)
19+
20+
# set horizontal progress bar width and height relative to board's display
21+
h_width = board.DISPLAY.width - 40
22+
h_height = 30
23+
24+
v_width = 30
25+
v_height = 140
26+
27+
h_x = 20
28+
h_y = 20
29+
30+
v_x = 60
31+
v_y = 70
32+
33+
# Create a new progress_bar objects at their x, y locations
34+
progress_bar = HorizontalProgressBar((h_x, h_y), (h_width, h_height), 0, 100)
35+
vert_progress_bar = VerticalProgressBar((v_x, v_y), (v_width, v_height), 0, 200)
36+
37+
# Append progress_bars to the splash group
38+
splash.append(progress_bar)
39+
splash.append(vert_progress_bar)
40+
41+
current_progress = 0.0
42+
while True:
43+
# range end is exclusive so we need to use 1 bigger than max number that we want
44+
for current_progress in range(0, 101, 1):
45+
print("Progress: {}%".format(current_progress))
46+
progress_bar.value = current_progress
47+
vert_progress_bar.value = current_progress * 2
48+
time.sleep(0.01)
49+
time.sleep(0.3)
50+
# reset to empty
51+
progress_bar.value = 0
52+
vert_progress_bar.value = 0
53+
time.sleep(0.3)

0 commit comments

Comments
 (0)