From 9333d800290af81f5f452c4c6b61cb91c4b270cb Mon Sep 17 00:00:00 2001 From: jposada202020 Date: Sat, 1 May 2021 12:06:56 -0400 Subject: [PATCH 1/2] adding new example showing the progress bar feature to change color programmatically --- docs/examples.rst | 10 +++ ...rogressbar_displayio_blinka_color_scale.py | 82 +++++++++++++++++++ examples/requirements.txt | 1 + 3 files changed, 93 insertions(+) create mode 100644 examples/progressbar_displayio_blinka_color_scale.py diff --git a/docs/examples.rst b/docs/examples.rst index 8358935..559e497 100644 --- a/docs/examples.rst +++ b/docs/examples.rst @@ -6,3 +6,13 @@ Ensure your device works with this simple test. .. literalinclude:: ../examples/progressbar_simpletest.py :caption: examples/progressbar_simpletest.py :linenos: + + +Color Scale +------------ + +Example showing how to change the progressbar color while updating the values + +.. literalinclude:: ../examples/progressbar_displayio_blinka_color_scale.py + :caption: examples/progressbar_displayio_blinka_color_scale.py + :linenos: diff --git a/examples/progressbar_displayio_blinka_color_scale.py b/examples/progressbar_displayio_blinka_color_scale.py new file mode 100644 index 0000000..ad7665a --- /dev/null +++ b/examples/progressbar_displayio_blinka_color_scale.py @@ -0,0 +1,82 @@ +#!/usr/bin/env python3 + +# SPDX-FileCopyrightText: 2021 Hugo Dahl for Adafruit Industries +# SPDX-FileCopyrightText: 2021 Jose David M. +# SPDX-License-Identifier: MIT + +# Before you can run this example, you will need to install the +# required libraries identifies in the `requirements.txt` file. +# You can do so automatically by using the "pip" utility. + +""" +Shows the ability of the progress bar to change color on the fly. +This example is and adaptation from the progressbar_displayio_blinka test +""" + +import time +import adafruit_fancyled.adafruit_fancyled as fancy +import displayio +from blinka_displayio_pygamedisplay import PyGameDisplay +from adafruit_progressbar.horizontalprogressbar import ( + HorizontalProgressBar, + HorizontalFillDirection, +) + +display = PyGameDisplay(width=320, height=240, auto_refresh=False) +splash = displayio.Group(max_size=10) +display.show(splash) + +# Setting up the grayscale values, You could use a different scale, and add more entries +# to have detailed transitions +# see learning guide regarding the FancyLed library +# https://learn.adafruit.com/fancyled-library-for-circuitpython/palettes +grad = [ + (0.0, 0x000000), + (0.20, 0x333333), + (0.40, 0x666666), + (0.60, 0x999999), + (0.80, 0xCCCCCC), + (1.0, 0xEEEEEE), +] + +# Creating the grayscale Palette using the FancyLed Library +palette = fancy.expand_gradient(grad, 50) + +colors = list() + +# We create an equal space palette. This is done for convenience and clarity as we use +# a value from 0 to 100 in our ProgressBar +for i in range(99): + color = fancy.palette_lookup(palette, i / 100) + colors.append(color.pack()) + +# Background creation +color_bitmap = displayio.Bitmap(display.width, display.height, 1) +color_palette = displayio.Palette(1) +color_palette[0] = 0x2266AA # Teal-ish-kinda + +bg_sprite = displayio.TileGrid(color_bitmap, pixel_shader=color_palette, x=0, y=0) +splash.append(bg_sprite) + + +horizontal_bar = HorizontalProgressBar( + (10, 80), + (180, 40), + fill_color=0x990099, + outline_color=0x0000FF, + bar_color=0x00FF00, + direction=HorizontalFillDirection.LEFT_TO_RIGHT, +) +splash.append(horizontal_bar) + +# List of step values for the progress bar +test_value_range_1 = [i for i in range(99)] + +# Must check display.running in the main loop! +while display.running: + print("\nDemonstration of values between 0 and 100 - Horizontal") + for val in test_value_range_1: + horizontal_bar.value = val + horizontal_bar.bar_color = colors[val] + display.refresh() + time.sleep(0.1) diff --git a/examples/requirements.txt b/examples/requirements.txt index ad621e7..f45c56d 100644 --- a/examples/requirements.txt +++ b/examples/requirements.txt @@ -9,3 +9,4 @@ Adafruit-Blinka adafruit-blinka-displayio blinka-displayio-pygamedisplay +adafruit-fancyled From a6c291c666a0f8eb34f421a4372e35fa46d58a24 Mon Sep 17 00:00:00 2001 From: jposada202020 Date: Sat, 1 May 2021 20:03:19 -0400 Subject: [PATCH 2/2] changing requirements.txt --- examples/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/requirements.txt b/examples/requirements.txt index f45c56d..1256b3d 100644 --- a/examples/requirements.txt +++ b/examples/requirements.txt @@ -9,4 +9,4 @@ Adafruit-Blinka adafruit-blinka-displayio blinka-displayio-pygamedisplay -adafruit-fancyled +adafruit-circuitpython-fancyled