|
| 1 | +# SPDX-FileCopyrightText: Copyright (c) 2021 GaryZ, Alec Delaney |
| 2 | +# |
| 3 | +# SPDX-License-Identifier: Unlicense |
| 4 | + |
| 5 | +""" |
| 6 | +Create multiple gauge's and change their level. |
| 7 | +This works on any CircuitPython device with a built-in display. |
| 8 | +""" |
| 9 | + |
| 10 | + |
| 11 | +import time |
| 12 | +import board |
| 13 | +import displayio |
| 14 | +from displayio_gauge import Gauge |
| 15 | +from displayio_effects import throttle_effect |
| 16 | + |
| 17 | +display = board.DISPLAY |
| 18 | + |
| 19 | +# Make the display context |
| 20 | +main_group = displayio.Group() |
| 21 | + |
| 22 | +# Make a background color fill |
| 23 | +color_bitmap = displayio.Bitmap(display.width, display.height, 1) |
| 24 | +color_palette = displayio.Palette(1) |
| 25 | +color_palette[0] = 0x000000 |
| 26 | +bg_sprite = displayio.TileGrid(color_bitmap, pixel_shader=color_palette, x=0, y=0) |
| 27 | +main_group.append(bg_sprite) |
| 28 | +display.show(main_group) |
| 29 | + |
| 30 | +throttle_effect.hook_throttle_effect(Gauge, "level") |
| 31 | + |
| 32 | +my_gauge = Gauge( |
| 33 | + x=90, |
| 34 | + y=50, |
| 35 | + radius=37, |
| 36 | + thickness=15, |
| 37 | + level=70, |
| 38 | + outline_color=0xFFFFFF, |
| 39 | + foreground_color=0x00FF00, |
| 40 | + background_color=0x000000, |
| 41 | +) |
| 42 | +main_group.append(my_gauge) |
| 43 | + |
| 44 | +my_gauge.throttle_effect = 1 |
| 45 | +my_gauge.throttle_effect_move_rate = 0.01 |
| 46 | + |
| 47 | + |
| 48 | +while True: |
| 49 | + |
| 50 | + my_gauge.throttle_update() |
| 51 | + display.refresh() |
0 commit comments