|
| 1 | +# SPDX-FileCopyrightText: 2021 Kevin Matocha |
| 2 | +# |
| 3 | +# SPDX-License-Identifier: MIT |
| 4 | +############################# |
| 5 | +# This is a trial of the Dial using Adafruit_DisplayIO_Layout |
| 6 | +# |
| 7 | + |
| 8 | +import time |
| 9 | +import board |
| 10 | +import displayio |
| 11 | +from adafruit_displayio_layout.widgets.dial import Dial |
| 12 | + |
| 13 | +from adafruit_bitmap_font import bitmap_font |
| 14 | + |
| 15 | +glyphs = "0123456789" |
| 16 | + |
| 17 | +# Fonts used for the Dial tick labels |
| 18 | +tick_font_file = "fonts/BitstreamVeraSans-Bold-16.pcf" |
| 19 | +tick_font = bitmap_font.load_font(tick_font_file) |
| 20 | +tick_font.load_glyphs(glyphs) |
| 21 | + |
| 22 | +display = board.DISPLAY # create the display on the PyPortal or Clue (for example) |
| 23 | +# otherwise change this to setup the display |
| 24 | +# for display chip driver and pinout you have (e.g. ILI9341) |
| 25 | + |
| 26 | + |
| 27 | +# Define the minimum and maximum values for the dial |
| 28 | +minimum_value = 0 |
| 29 | +maximum_value = 100 |
| 30 | + |
| 31 | +# Create a Dial widget |
| 32 | +my_dial = Dial( |
| 33 | + x=20, # set x-position of the dial inside of my_group |
| 34 | + y=20, # set y-position of the dial inside of my_group |
| 35 | + width=180, # requested width of the di |
| 36 | + height=180, |
| 37 | + padding=25, # add 25 pixels around the dial to make room for labels |
| 38 | + start_angle=-120, # left angle position at -120 degrees |
| 39 | + sweep_angle=240, # total sweep angle of 240 degrees |
| 40 | + min_value=minimum_value, # set the minimum value shown on the dial |
| 41 | + max_value=maximum_value, # set the maximum value shown on the dial |
| 42 | + tick_label_font=tick_font, # |
| 43 | +) |
| 44 | + |
| 45 | +my_group = displayio.Group(max_size=1) |
| 46 | +my_group.append(my_dial) |
| 47 | + |
| 48 | +display.show(my_group) # add high level Group to the display |
| 49 | + |
| 50 | +step_size = 1 |
| 51 | + |
| 52 | +while True: |
| 53 | + |
| 54 | + # run the dial from minimum to maximum |
| 55 | + for this_value in range(minimum_value, maximum_value + 1, step_size): |
| 56 | + my_dial.value = this_value |
| 57 | + display.refresh() # force the display to refresh |
| 58 | + time.sleep(0.5) |
| 59 | + |
| 60 | + # run the dial from maximum to minimum |
| 61 | + for this_value in range(maximum_value, minimum_value - 1, -step_size): |
| 62 | + my_dial.value = this_value |
| 63 | + display.refresh() # force the display to refresh |
| 64 | + time.sleep(0.5) |
0 commit comments