Simple test

Ensure your device works with this simple test.

examples/progressbar_simpletest.py
 1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
 2# SPDX-License-Identifier: MIT
 3
 4import time
 5import board
 6import displayio
 7from adafruit_progressbar.horizontalprogressbar import (
 8    HorizontalProgressBar,
 9    HorizontalFillDirection,
10)
11
12# Make the display context
13splash = displayio.Group()
14board.DISPLAY.show(splash)
15
16# set progress bar width and height relative to board's display
17width = board.DISPLAY.width - 40
18height = 30
19
20x = board.DISPLAY.width // 2 - width // 2
21y = board.DISPLAY.height // 3
22
23# Create a new progress_bar object at (x, y)
24progress_bar = HorizontalProgressBar(
25    (x, y), (width, height), direction=HorizontalFillDirection.LEFT_TO_RIGHT
26)
27
28# Append progress_bar to the splash group
29splash.append(progress_bar)
30
31current_value = progress_bar.minimum
32while True:
33    # range end is exclusive so we need to use 1 bigger than max number that we want
34    for current_value in range(progress_bar.minimum, progress_bar.maximum + 1, 1):
35        print("Progress: {}%".format(current_value))
36        progress_bar.value = current_value
37        time.sleep(0.01)
38    time.sleep(0.3)
39    progress_bar.value = progress_bar.minimum
40    time.sleep(0.3)

Color Scale

Example showing how to change the progressbar color while updating the values

examples/progressbar_displayio_blinka_color_scale.py
 1#!/usr/bin/env python3
 2
 3# SPDX-FileCopyrightText: 2021 Hugo Dahl for Adafruit Industries
 4# SPDX-FileCopyrightText: 2021 Jose David M.
 5# SPDX-License-Identifier: MIT
 6
 7# Before you can run this example, you will need to install the
 8# required libraries identifies in the `requirements.txt` file.
 9# You can do so automatically by using the "pip" utility.
10
11"""
12Shows the ability of the progress bar to change color on the fly.
13This example is and adaptation from the progressbar_displayio_blinka test
14"""
15
16import time
17import adafruit_fancyled.adafruit_fancyled as fancy
18import displayio
19from blinka_displayio_pygamedisplay import PyGameDisplay
20from adafruit_progressbar.horizontalprogressbar import (
21    HorizontalProgressBar,
22    HorizontalFillDirection,
23)
24
25display = PyGameDisplay(width=320, height=240, auto_refresh=False)
26splash = displayio.Group()
27display.show(splash)
28
29# Setting up the grayscale values, You could use a different scale, and add more entries
30# to have detailed transitions
31# see learning guide regarding the FancyLed library
32# https://learn.adafruit.com/fancyled-library-for-circuitpython/palettes
33grad = [
34    (0.0, 0x000000),
35    (0.20, 0x333333),
36    (0.40, 0x666666),
37    (0.60, 0x999999),
38    (0.80, 0xCCCCCC),
39    (1.0, 0xEEEEEE),
40]
41
42# Creating the grayscale Palette using the FancyLed Library
43palette = fancy.expand_gradient(grad, 50)
44
45colors = []
46
47# We create an equal space palette. This is done for convenience and clarity as we use
48# a value from 0 to 100 in our ProgressBar
49for i in range(99):
50    color = fancy.palette_lookup(palette, i / 100)
51    colors.append(color.pack())
52
53# Background creation
54color_bitmap = displayio.Bitmap(display.width, display.height, 1)
55color_palette = displayio.Palette(1)
56color_palette[0] = 0x2266AA  # Teal-ish-kinda
57
58bg_sprite = displayio.TileGrid(color_bitmap, pixel_shader=color_palette, x=0, y=0)
59splash.append(bg_sprite)
60
61
62horizontal_bar = HorizontalProgressBar(
63    (10, 80),
64    (180, 40),
65    fill_color=0x990099,
66    outline_color=0x0000FF,
67    bar_color=0x00FF00,
68    direction=HorizontalFillDirection.LEFT_TO_RIGHT,
69)
70splash.append(horizontal_bar)
71
72# List of step values for the progress bar
73test_value_range_1 = list(range(99))
74
75# Must check display.running in the main loop!
76while display.running:
77    print("\nDemonstration of values between 0 and 100 - Horizontal")
78    for val in test_value_range_1:
79        horizontal_bar.value = val
80        horizontal_bar.bar_color = colors[val]
81        display.refresh()
82        time.sleep(0.1)

Vertical Simple test

Simple test to show a vertical Progress bar

examples/progressbar_vertical_simpletest.py
 1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
 2# SPDX-License-Identifier: MIT
 3
 4import time
 5import board
 6import displayio
 7from adafruit_progressbar.verticalprogressbar import (
 8    VerticalProgressBar,
 9    VerticalFillDirection,
10)
11
12# Make the display context
13splash = displayio.Group()
14board.DISPLAY.show(splash)
15
16# set progress bar width and height relative to board's display
17width = 10
18height = board.DISPLAY.height - 40
19
20x = width * 2
21y = 10
22
23# Create a new VerticalProgressBar object at (x, y)
24vertical_progress_bar = VerticalProgressBar(
25    (x, y), (width, height), direction=VerticalFillDirection.TOP_TO_BOTTOM
26)
27
28# Append progress_bar to the splash group
29splash.append(vertical_progress_bar)
30
31x = x * 2
32# Create a second VerticalProgressBar object at (x+20, y)
33vertical_progress_bar2 = VerticalProgressBar(
34    (x, y), (width, height), direction=VerticalFillDirection.BOTTOM_TO_TOP
35)
36
37# Append progress_bar to the splash group
38splash.append(vertical_progress_bar2)
39
40
41current_progress = 0.0
42while 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        vertical_progress_bar.value = current_progress
47        vertical_progress_bar2.value = current_progress
48        time.sleep(0.05)
49    time.sleep(0.3)
50    vertical_progress_bar.value = vertical_progress_bar.minimum
51    vertical_progress_bar2.value = vertical_progress_bar.minimum
52    time.sleep(0.3)

MatrixPortal Example

Progressbar using the MatrixPortal

examples/examples/progressbar_matrixportal.py
  1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
  2# SPDX-License-Identifier: MIT
  3
  4# Source: https://github.com/ajs256/matrixportal-weather-display
  5
  6# ############## IMPORTS ###############
  7
  8# HARDWARE
  9import time
 10import board
 11
 12# DISPLAY
 13import displayio  # Main display library
 14import framebufferio  # For showing things on the display
 15import rgbmatrix  # For talking to matrices specifically
 16
 17# CONTROLS
 18
 19import digitalio
 20
 21from adafruit_progressbar.horizontalprogressbar import (
 22    HorizontalProgressBar,
 23    HorizontalFillDirection,
 24)
 25from adafruit_progressbar.verticalprogressbar import (
 26    VerticalProgressBar,
 27    VerticalFillDirection,
 28)
 29
 30# ############## DISPLAY SETUP ###############
 31
 32# If there was a display before (protomatter, LCD, or E-paper), release it so
 33# we can create ours
 34displayio.release_displays()
 35
 36print("Setting up RGB matrix")
 37
 38# This next call creates the RGB Matrix object itself. It has the given width
 39# and height.
 40#
 41# These lines are for the Matrix Portal. If you're using a different board,
 42# check the guide to find the pins and wiring diagrams for your board.
 43# If you have a matrix with a different width or height, change that too.
 44matrix = rgbmatrix.RGBMatrix(
 45    width=64,
 46    height=32,
 47    bit_depth=3,
 48    rgb_pins=[
 49        board.MTX_R1,
 50        board.MTX_G1,
 51        board.MTX_B1,
 52        board.MTX_R2,
 53        board.MTX_G2,
 54        board.MTX_B2,
 55    ],
 56    addr_pins=[board.MTX_ADDRA, board.MTX_ADDRB, board.MTX_ADDRC, board.MTX_ADDRD],
 57    clock_pin=board.MTX_CLK,
 58    latch_pin=board.MTX_LAT,
 59    output_enable_pin=board.MTX_OE,
 60)
 61
 62# Associate the RGB matrix with a Display so that we can use displayio features
 63display = framebufferio.FramebufferDisplay(matrix)
 64
 65print("Adding display group")
 66group = displayio.Group()  # Create a group to hold all our labels
 67display.show(group)
 68
 69print("Creating progress bars and adding to group")
 70
 71# A horizontal percentage progress bar, valued at 60%
 72progress_bar = HorizontalProgressBar((2, 8), (40, 8), value=60)
 73group.insert(0, progress_bar)
 74
 75# Another progress bar, with explicit range and fill from the right
 76ranged_bar = HorizontalProgressBar(
 77    (2, 20),
 78    (40, 8),
 79    value=40,
 80    min_value=0,
 81    max_value=100,
 82    direction=HorizontalFillDirection.RIGHT_TO_LEFT,
 83)
 84group.insert(1, ranged_bar)
 85
 86# Sample thermometer from -40C to 50C, with a value of +15C
 87vertical_bar = VerticalProgressBar(
 88    (44, 4),
 89    (8, 24),
 90    min_value=-40,
 91    max_value=50,
 92    value=15,
 93    bar_color=0x1111FF,
 94    fill_color=None,
 95    margin_size=0,
 96    outline_color=0x2222AA,
 97)
 98group.insert(2, vertical_bar)
 99
100vertical_bar2 = VerticalProgressBar(
101    (54, 4),
102    (8, 24),
103    min_value=-40,
104    max_value=50,
105    value=15,
106    bar_color=0x1111FF,
107    fill_color=None,
108    margin_size=0,
109    outline_color=0x2222AA,
110    direction=VerticalFillDirection.TOP_TO_BOTTOM,
111)
112group.insert(3, vertical_bar2)
113
114# Countdown to the start of the bars demo
115countdown_bar = HorizontalProgressBar(
116    (2, 2),
117    (20, 5),
118    0,
119    5,
120    value=5,
121    bar_color=0x11FF11,
122    fill_color=0x333333,
123    border_thickness=0,
124    margin_size=0,
125)
126
127countdown_end_color = 0xFF1111
128
129group.insert(4, countdown_bar)
130# group.insert(0, countdown_bar)
131
132print("Progress bars added. Starting demo...")
133
134print("Using countdown bar")
135
136for timer in range(countdown_bar.maximum, countdown_bar.minimum, -1):
137    bar_color_to_set = (0x20 * (6 - timer) + 20, (0x20 * (timer - 1)) + 20, 0x10)
138    countdown_bar.bar_color = bar_color_to_set
139    countdown_bar.value = timer
140    time.sleep(1)
141
142print("Removing countdown bar")
143
144countdown_bar.value = 0
145group.remove(countdown_bar)
146
147progress_bar_value = 0.0
148progress_bar_incr = 3.0
149
150button1 = digitalio.DigitalInOut(board.BUTTON_UP)
151button1.switch_to_input(digitalio.Pull.UP)
152button2 = digitalio.DigitalInOut(board.BUTTON_DOWN)
153button2.switch_to_input(digitalio.Pull.UP)
154
155
156print("Start forever loop")
157while True:
158
159    print("Setting progress bar value to", progress_bar_value)
160
161    progress_bar.value = progress_bar_value
162    ranged_bar.value = progress_bar_value
163    progress_bar_value += progress_bar_incr
164
165    if not (button1.value and button2.value):
166
167        if not button1.value:  # "UP" button pushed
168            print("UP button pressed. Increasing vertical bars by 3")
169            vertical_bar.value = min(vertical_bar.maximum, vertical_bar.value + 3)
170            vertical_bar2.value = min(vertical_bar2.maximum, vertical_bar2.value + 3)
171
172        if not button2.value:  # "DOWN" button pushed
173            print("DOWN button pressed. Decreasing vertical bars by 3")
174            vertical_bar.value = max(vertical_bar.minimum, vertical_bar.value - 3)
175            vertical_bar2.value = max(vertical_bar2.minimum, vertical_bar2.value - 3)
176
177    if progress_bar_value > progress_bar.maximum:
178        progress_bar_value = progress_bar.maximum
179        progress_bar_incr *= -1
180
181    if progress_bar_value < progress_bar.minimum:
182        progress_bar_value = progress_bar.minimum
183        progress_bar_incr *= -1
184
185    time.sleep(0.5)

MagTag Example

Progressbar using the MagTag

examples/progressbar_magtag_simpletest.py
 1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
 2# SPDX-License-Identifier: MIT
 3
 4"""
 5Basic progressbar example script
 6adapted for use on MagTag.
 7"""
 8import time
 9import board
10import displayio
11import digitalio
12from adafruit_progressbar.progressbar import HorizontalProgressBar
13
14# use built in display (PyPortal, PyGamer, PyBadge, CLUE, etc.)
15# see guide for setting up external displays (TFT / OLED breakouts, RGB matrices, etc.)
16# https://learn.adafruit.com/circuitpython-display-support-using-displayio/display-and-display-bus
17display = board.DISPLAY
18time.sleep(display.time_to_refresh)
19
20# B/up button will be used to increase the progress
21up_btn = digitalio.DigitalInOut(board.BUTTON_B)
22up_btn.direction = digitalio.Direction.INPUT
23up_btn.pull = digitalio.Pull.UP
24
25# C/down button will be used to increase the progress
26down_btn = digitalio.DigitalInOut(board.BUTTON_C)
27down_btn.direction = digitalio.Direction.INPUT
28down_btn.pull = digitalio.Pull.UP
29
30# Make the display context
31splash = displayio.Group()
32display.show(splash)
33
34# set progress bar width and height relative to board's display
35BAR_WIDTH = display.width - 40
36BAR_HEIGHT = 30
37
38x = display.width // 2 - BAR_WIDTH // 2
39y = display.height // 3
40
41# Create a new progress_bar object at (x, y)
42progress_bar = HorizontalProgressBar(
43    (x, y),
44    (BAR_WIDTH, BAR_HEIGHT),
45    bar_color=0xFFFFFF,
46    outline_color=0xAAAAAA,
47    fill_color=0x777777,
48)
49
50# Append progress_bar to the splash group
51splash.append(progress_bar)
52
53# Get a random starting value within our min/max range
54current_progress = time.monotonic() % 101
55print(current_progress)
56progress_bar.value = current_progress
57
58# refresh the display
59display.refresh()
60
61value_incrementor = 3
62
63prev_up = up_btn.value
64prev_down = down_btn.value
65while True:
66    cur_up = up_btn.value
67    cur_down = down_btn.value
68    do_refresh = False
69    # if up_btn was just pressed down
70    if not cur_up and prev_up:
71        current_progress += value_incrementor
72        # Wrap if we get over the maximum value
73        if current_progress > progress_bar.maximum:
74            current_progress = progress_bar.minimum
75
76        do_refresh = True
77
78    if not cur_down and prev_down:
79        current_progress -= value_incrementor
80        # Wrap if we get below the minimum value
81        if current_progress < progress_bar.minimum:
82            current_progress = progress_bar.maximum
83
84        do_refresh = True
85
86    if do_refresh:
87        print(current_progress)
88        progress_bar.value = current_progress
89
90        time.sleep(display.time_to_refresh)
91        display.refresh()
92        time.sleep(display.time_to_refresh)
93
94    prev_up = cur_up
95    prev_down = cur_down

DisplayIO Blinka

Progressbar using DisplayIO in Blinka

examples/progressbar_displayio_blinka.py
  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
 10import time
 11import sys
 12import displayio
 13from blinka_displayio_pygamedisplay import PyGameDisplay
 14from adafruit_progressbar.progressbar import ProgressBar
 15from adafruit_progressbar.horizontalprogressbar import (
 16    HorizontalProgressBar,
 17    HorizontalFillDirection,
 18)
 19from adafruit_progressbar.verticalprogressbar import (
 20    VerticalProgressBar,
 21    VerticalFillDirection,
 22)
 23
 24display = PyGameDisplay(width=320, height=240, auto_refresh=False)
 25splash = displayio.Group()
 26display.show(splash)
 27
 28color_bitmap = displayio.Bitmap(display.width, display.height, 1)
 29color_palette = displayio.Palette(1)
 30color_palette[0] = 0x2266AA  # Teal-ish-kinda
 31
 32bg_sprite = displayio.TileGrid(color_bitmap, pixel_shader=color_palette, x=0, y=0)
 33splash.append(bg_sprite)
 34
 35progress_bar = ProgressBar(
 36    width=180,
 37    height=40,
 38    x=10,
 39    y=20,
 40    progress=0.0,
 41    bar_color=0x1100FF,
 42    outline_color=0x777777,
 43)
 44splash.append(progress_bar)
 45
 46horizontal_bar = HorizontalProgressBar(
 47    (10, 80),
 48    (180, 40),
 49    fill_color=0x778822,
 50    outline_color=0x0000FF,
 51    bar_color=0x00FF00,
 52    direction=HorizontalFillDirection.LEFT_TO_RIGHT,
 53)
 54splash.append(horizontal_bar)
 55
 56horizontal_thermometer = HorizontalProgressBar(
 57    (10, 140),
 58    (180, 40),
 59    value=-10,
 60    min_value=(-40),
 61    max_value=130,
 62    fill_color=0x00FF00,
 63    outline_color=0x0000FF,
 64    bar_color=0x22BB88,
 65    direction=HorizontalFillDirection.RIGHT_TO_LEFT,
 66)
 67splash.append(horizontal_thermometer)
 68
 69vertical_bar = VerticalProgressBar(
 70    (200, 30),
 71    (32, 180),
 72    direction=VerticalFillDirection.TOP_TO_BOTTOM,
 73)
 74splash.append(vertical_bar)
 75
 76vertical_thermometer = VerticalProgressBar(
 77    (260, 30),
 78    (32, 180),
 79    min_value=-40,
 80    max_value=130,
 81    direction=VerticalFillDirection.BOTTOM_TO_TOP,
 82)
 83splash.append(vertical_thermometer)
 84
 85test_value_range_1 = [99, 100, 99, 1, 0, 1]
 86test_value_range_2 = [120, 130, 129, -20, -39, -40, -28]
 87delay = 2
 88_incr = 1
 89
 90# Must check display.running in the main loop!
 91while display.running:
 92
 93    print("\nDemonstration of legacy functionality and syntax, increment by 0.01")
 94    for val in range(0, 101):
 95        if not display.running:
 96            sys.exit(0)
 97        _use_value = round((val * 0.01), 2)
 98        if (val % 10) == 0:
 99            print(f"Value has reached {_use_value:2}")
100        progress_bar.progress = round(_use_value, 2)
101        display.refresh()
102        time.sleep(0.05)
103
104    print("\nDemonstration of values between 0 and 100 - Horizontal and vertical")
105    for val in test_value_range_1:
106        if not display.running:
107            sys.exit(0)
108        print(f"Setting value to {val}")
109        vertical_bar.value = val
110        horizontal_bar.value = val
111        display.refresh()
112        time.sleep(delay)
113
114    print("\nDemonstration of Fahrenheit range -40 and 130 - Horizontal and vertical")
115    for val in test_value_range_2:
116        if not display.running:
117            sys.exit(0)
118        print(f"Setting value to {val}")
119        vertical_thermometer.value = val
120        horizontal_thermometer.value = val
121        display.refresh()
122        time.sleep(delay)

Combined ProgressBar

Example showing both a Vertical and an Horizontal ProgressBar

examples/progressbar_combined.py
 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
10import time
11import board
12import displayio
13from adafruit_progressbar.horizontalprogressbar import HorizontalProgressBar
14from adafruit_progressbar.verticalprogressbar import VerticalProgressBar
15
16# Make the display context
17splash = displayio.Group()
18board.DISPLAY.show(splash)
19
20# set horizontal progress bar width and height relative to board's display
21h_width = board.DISPLAY.width - 40
22h_height = 30
23
24v_width = 30
25v_height = 140
26
27h_x = 20
28h_y = 20
29
30v_x = 60
31v_y = 70
32
33# Create a new progress_bar objects at their x, y locations
34progress_bar = HorizontalProgressBar((h_x, h_y), (h_width, h_height), 0, 100)
35vert_progress_bar = VerticalProgressBar((v_x, v_y), (v_width, v_height), 0, 200)
36
37# Append progress_bars to the splash group
38splash.append(progress_bar)
39splash.append(vert_progress_bar)
40
41current_progress = 0.0
42while 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)

Accelerometer Example

With this example you would be able to use the progress bar to display accelerometer data in the X and Y directions

examples/progressbar_accelerometer.py
  1# SPDX-FileCopyrightText: 2021 Jose David M.
  2# SPDX-License-Identifier: MIT
  3"""
  4With this example you would be able to use the progress bar to display accelerometer data
  5in the X and Y directions
  6"""
  7import time
  8import displayio
  9import board
 10from adafruit_progressbar.horizontalprogressbar import (
 11    HorizontalProgressBar,
 12    HorizontalFillDirection,
 13)
 14from adafruit_progressbar.verticalprogressbar import (
 15    VerticalProgressBar,
 16    VerticalFillDirection,
 17)
 18
 19# This data is used to show library capability. You could use an actual accelerometer
 20# This data was extracted from an Adafruit MSA301 Triple Axis Accelerometer
 21fake__accel_data = [
 22    (-0.071821, 1.450790, 9.533077),
 23    (-0.105338, 1.939175, 9.111725),
 24    (-0.306437, 2.906367, 9.178761),
 25    (-0.062245, 3.504878, 8.776562),
 26    (-0.143643, 4.792873, 8.091862),
 27    (-0.172371, 5.520662, 7.838097),
 28    (0.014364, 6.176630, 7.426321),
 29    (-0.205888, 7.526871, 6.200571),
 30    (-0.090974, 7.905128, 5.491934),
 31    (-0.445292, 8.216354, 5.118464),
 32    (-0.110126, 8.872322, 4.017202),
 33    (-0.344742, 9.542652, 1.498671),
 34    (-0.076609, 9.580959, -0.033517),
 35    (-0.158007, 9.518715, -1.273631),
 36    (0.282497, 9.446892, -2.877639),
 37    (-0.004788, 9.063847, -3.409117),
 38    (-0.153219, 8.599400, -4.630077),
 39    (-0.071821, 8.020042, -6.382517),
 40    (0.655968, 6.722471, -6.937935),
 41    (0.464444, 5.740913, -7.771063),
 42    (1.034226, 4.189575, -8.905838),
 43    (1.369392, 1.675830, -8.340843),
 44    (2.149850, -1.426849, -9.178761),
 45    (2.384466, -3.662886, -8.834019),
 46    (2.417983, -5.223801, -7.957798),
 47    (2.336586, -7.900341, -5.482357),
 48    (2.106757, -9.231426, -4.194363),
 49    (1.948751, -3.945382, -9.288883),
 50    (0.588934, 0.062245, -9.643204),
 51    (0.430928, 2.250400, -9.360706),
 52    (-0.402199, 7.249161, -6.176630),
 53    (-0.871432, 8.197201, -5.003550),
 54    (0.373471, 8.829227, -3.696402),
 55    (0.584146, 9.662357, -1.287995),
 56    (0.114914, 9.940063, 0.536266),
 57    (-0.201100, 9.207489, 2.848910),
 58    (-0.181947, 8.589825, 5.314775),
 59    (-0.517113, 5.573332, 7.598692),
 60    (-0.497961, 3.160136, 9.092575),
 61    (-0.114914, -1.541763, 9.940063),
 62    (-0.555418, -5.099310, 7.727970),
 63    (-0.387835, -7.091154, 7.095942),
 64    (0.162795, -8.652069, 4.768932),
 65    (0.531477, -8.934566, 0.751729),
 66    (0.775670, -9.542652, -4.141693),
 67    (1.809896, -7.177340, -7.282679),
 68    (0.957617, -2.868063, -9.308037),
 69    (1.450790, -0.866643, -9.571381),
 70    (1.039014, -0.660756, -9.758118),
 71    (0.914524, -4.907787, -8.379150),
 72    (1.302359, -8.120594, -5.870192),
 73    (1.043803, -9.916122, 2.365314),
 74    (1.086895, -8.412666, 5.223801),
 75    (2.034936, -5.942015, 7.488565),
 76    (2.010996, -2.767513, 9.140453),
 77    (0.397411, -2.322221, 9.130878),
 78    (-2.025360, -2.398830, 9.116512),
 79    (-2.824970, -2.264764, 8.896263),
 80    (-4.395462, -2.001419, 8.259445),
 81    (-5.640364, -1.220962, 7.569963),
 82    (-7.000181, -0.746941, 6.679379),
 83    (-8.077499, -0.004788, 5.338715),
 84    (-9.001598, 0.421352, 2.585566),
 85    (-9.408588, 1.106048, 1.053379),
 86    (-9.097363, 2.283916, -1.589644),
 87    (-8.522793, 2.714845, -3.021282),
 88    (-7.991314, 3.083527, -4.505589),
 89    (-6.416035, 3.720343, -6.732048),
 90    (-6.186207, 3.562336, -5.788795),
 91    (-3.289414, 3.428269, -8.254658),
 92    (-1.110836, 3.787375, -8.944141),
 93    (1.082107, 3.270263, -9.059055),
 94    (1.565704, 3.820892, -8.446182),
 95    (2.212095, 3.763435, -8.221142),
 96    (3.030858, 4.175211, -8.029617),
 97    (-2.365314, 2.633447, -8.221142),
 98    (-5.372232, 2.188155, -7.445473),
 99    (-8.465336, 2.116334, -4.577410),
100    (-9.432529, 1.388545, 0.541054),
101    (-6.957088, 1.623161, 6.085657),
102    (-4.735416, 0.751729, 8.992023),
103    (-1.800320, 2.063664, 9.762905),
104    (-0.153219, -1.795532, 9.657566),
105    (5.764854, -3.801740, 6.775141),
106    (9.470833, -2.240824, 2.777089),
107    (9.925701, -1.000710, -1.915234),
108    (8.685585, 0.277709, -4.347582),
109    (9.676720, -0.459656, -0.521901),
110    (9.719814, -0.689484, 1.584856),
111    (8.541943, -1.503459, 4.160847),
112    (7.608267, -1.824261, 5.865404),
113    (5.817524, -1.446002, 6.770353),
114    (3.887925, -1.991844, 8.671223),
115    (1.805108, -2.039724, 9.303249),
116    (0.593723, -1.690194, 9.518715),
117    (0.852279, -2.087605, 9.427738),
118    (1.206597, -1.857777, 9.226639),
119    (0.392623, -2.255188, 9.193123),
120    (-2.475440, -2.154638, 9.173969),
121    (-3.677250, -8.288174, 3.198441),
122    (-0.981558, -2.944673, 8.977661),
123    (1.517823, 3.409117, 8.977661),
124    (2.796242, 5.989895, 5.807947),
125    (4.151270, -2.552050, 9.418163),
126    (4.242243, -9.844303, 1.694982),
127    (5.946802, -3.543183, 6.890055),
128    (7.028910, -4.462496, 4.199150),
129    (-1.694982, -6.655439, 6.430399),
130    (0.703849, -3.112255, 8.685585),
131    (1.340664, 4.342793, 8.053558),
132    (1.627949, 9.920914, -0.608087),
133    (6.985817, 0.517113, 7.517294),
134    (5.434477, -5.372232, 5.994682),
135    (4.165634, -6.224510, 8.082287),
136    (0.847491, -4.677959, 9.509136),
137    (3.476150, -4.812025, 7.421532),
138]
139display = board.DISPLAY
140main_group = displayio.Group()
141display.show(main_group)
142
143color_bitmap = displayio.Bitmap(display.width, display.height, 1)
144color_palette = displayio.Palette(1)
145color_palette[0] = 0x990099
146
147background = displayio.TileGrid(color_bitmap, pixel_shader=color_palette, x=0, y=0)
148main_group.append(background)
149
150# Accelerometer Properties. Normally accelerometer well calibrated
151# Will give a maximum output of 10 mts / s**2
152VALUES_X = (-10, 10)
153VALUES_Y = (-10, 10)
154
155# Horizontal Bar Properties
156HORIZONTAL_BAR_X_ORIGIN = 10
157HORIZONTAL_BAR_Y_ORIGIN = 30
158HORIZONTAL_BAR_WIDTH = display.width // 4
159HORIZONTAL_BAR_HEIGHT = 30
160
161# Vertical Bar Properties
162VERTICAL_BAR_HEIGHT = display.height // 4
163VERTICAL_BAR_WIDTH = 30
164
165# We create our bar displays
166left_horizontal_bar = HorizontalProgressBar(
167    (HORIZONTAL_BAR_X_ORIGIN, HORIZONTAL_BAR_Y_ORIGIN),
168    (HORIZONTAL_BAR_WIDTH, HORIZONTAL_BAR_HEIGHT),
169    min_value=0,
170    max_value=-VALUES_X[0],
171    direction=HorizontalFillDirection.RIGHT_TO_LEFT,
172)
173main_group.append(left_horizontal_bar)
174
175right_horizontal_bar = HorizontalProgressBar(
176    (HORIZONTAL_BAR_X_ORIGIN + HORIZONTAL_BAR_WIDTH, HORIZONTAL_BAR_Y_ORIGIN),
177    (HORIZONTAL_BAR_WIDTH, HORIZONTAL_BAR_HEIGHT),
178    min_value=0,
179    max_value=VALUES_X[1],
180    direction=HorizontalFillDirection.LEFT_TO_RIGHT,
181)
182main_group.append(right_horizontal_bar)
183
184
185top_vertical_bar = VerticalProgressBar(
186    (HORIZONTAL_BAR_X_ORIGIN + 2 * HORIZONTAL_BAR_WIDTH + 20, HORIZONTAL_BAR_Y_ORIGIN),
187    (VERTICAL_BAR_WIDTH, VERTICAL_BAR_HEIGHT),
188    min_value=0,
189    max_value=VALUES_Y[1],
190    direction=VerticalFillDirection.BOTTOM_TO_TOP,
191)
192main_group.append(top_vertical_bar)
193
194bottom_vertical_bar = VerticalProgressBar(
195    (
196        HORIZONTAL_BAR_X_ORIGIN + 2 * HORIZONTAL_BAR_WIDTH + 20,
197        HORIZONTAL_BAR_Y_ORIGIN + VERTICAL_BAR_HEIGHT,
198    ),
199    (VERTICAL_BAR_WIDTH, VERTICAL_BAR_HEIGHT),
200    min_value=0,
201    max_value=-VALUES_Y[0],
202    direction=VerticalFillDirection.TOP_TO_BOTTOM,
203)
204main_group.append(bottom_vertical_bar)
205
206delay = 0.5
207
208while True:
209    for val in fake__accel_data:
210        if val[0] >= 0:
211            left_horizontal_bar.value = 0
212            right_horizontal_bar.value = val[0]
213        if val[0] < 0:
214            left_horizontal_bar.value = -val[0]
215            right_horizontal_bar.value = 0
216
217        if val[1] >= 0:
218            top_vertical_bar.value = val[1]
219            bottom_vertical_bar.value = 0
220        if val[1] < 0:
221            bottom_vertical_bar.value = -val[1]
222            top_vertical_bar.value = 0
223
224        display.refresh()
225        time.sleep(delay)