Introduction¶
Allows display data in a graduated level
Dependencies¶
This driver depends on:
Please ensure all dependencies are available on the CircuitPython filesystem. This is easily achieved by downloading the Adafruit library and driver bundle or individual libraries can be installed using circup.
Usage Example¶

Please se the scales_simpletest.py
example for initial reference
Contributing¶
Contributions are welcome! Please read our Code of Conduct before contributing to help this project stay welcoming.
Documentation¶
For information on building library documentation, please check out this guide.
Table of Contents¶
Simple test¶
Ensure your device works with this simple test.
1import time
2import board
3import displayio
4from scales import Scale
5
6display = board.DISPLAY
7group = displayio.Group()
8
9values = [56, 58, 60, 65, 63, 60, 56, 54, 53, 42, 43, 44, 45, 52, 54]
10
11my_scale = Scale(
12 x=50,
13 y=220,
14 length=200,
15 direction="vertical",
16 limits=(0, 80),
17 ticks=[16, 32, 48, 64, 80],
18)
19
20group.append(my_scale)
21
22my_scale2 = Scale(
23 x=150,
24 y=100,
25 length=200,
26 direction="horizontal",
27 limits=(0, 80),
28 ticks=[16, 32, 48, 64, 80],
29)
30group.append(my_scale2)
31display.show(group)
32
33
34while True:
35 for val in values:
36 my_scale.animate_pointer(val)
37 my_scale2.animate_pointer(val)
38 time.sleep(0.1)
Scales Library¶
scales
¶
Allows display data in a graduated level
Author(s): Jose David M.
Implementation Notes¶
Scales version in CircuitPython
- class scales.Axes(*args: Any, **kwargs: Any)¶
- Parameters:
x (int) – pixel position. Defaults to
0
y (int) – pixel position. Defaults to
0
limits (int,int) – tuple of value range for the scale. Defaults to (0, 100)
ticks (list) – list to ticks to display. If this is not enter a equally spaced scale will be created between the given limits.
direction (str) – direction of the scale either
horizontal
orvertical
defaults tohorizontal
stroke (int) – width in pixels of the scale axes. Defaults to
3
length (int) – scale length in pixels. Defaults to
100
color (int) – 24-bit hex value axes line color, Defaults to Purple
0x990099
- class scales.Scale(*args: Any, **kwargs: Any)¶
- Parameters:
x (int) – pixel position. Defaults to
0
y (int) – pixel position. Defaults to
0
direction (str) – direction of the scale either
horizontal
orvertical
defaults tohorizontal
stroke (int) – width in pixels of the axes line. Defaults to
3
pixelslength (int) – scale length in pixels. Defaults to
100
pixelscolor (int) – 24-bit hex value axes line color, Defaults to Purple
0x990099
width (int) – scale width in pixels. Defaults to
50
pixelslimits – tuple of value range for the scale. Defaults to
(0, 100)
ticks (list) – list to ticks to display. If this is not enter a equally spaced scale will be created between the given limits.
back_color (int) – 24-bit hex value axes line color. Defaults to Light Blue
0x9FFFFF
tick_length (int) – Scale tick length in pixels. Defaults to
10
tick_stroke (int) – Scale tick width in pixels. Defaults to
4
pointer_length (int) – length in pixels for the point. Defaults to
20
pixelspointer_stroke (int) – pointer thickness in pixels. Defaults to
6
pixels
Quickstart: Importing and using Scales
Here is one way of importing the
Scale
class, so you can use it as the namemy_scale
:from scale import Scale
Now you can create a vertical Scale at pixel position x=50, y=180 and a range of 0 to 80 using:
my_scale = Scale(x=50, y=180, direction="vertical", limits=(0, 80))
Once you setup your display, you can now add
my_scale
to your display using:display.show(my_scale)
If you want to have multiple display elements, you can create a group and then append the scale and the other elements to the group. Then, you can add the full group to the display as in this example:
my_scale= Scale(x=20, y=30) my_group = displayio.Group() # make a group my_group.append(my_scale) # Add my_slider to the group # # Append other display elements to the group # display.show(my_group) # add the group to the display
Summary: Slider Features and input variables
The
Scale
class has some options for controlling its position, visible appearance, and value through a collection of input variables:position:
x`
,y
size:
length
andwidth
color:
color
,back_color
linewidths:
stroke
andtick_stroke
range:
limits
Diagram showing a simple scale.¶
- animate_pointer(new_value)¶
Public function to animate the pointer
- Parameters:
new_value – value to draw the pointer
- Returns:
None
- scales.rectangle_draw(x0: int, y0: int, height: int, width: int, palette)¶
rectangle_draw function
Draws a rectangle using or
vectorio.Rectangle
- scales.transform(oldrangemin: Union[float, int], oldrangemax: Union[float, int], newrangemin: Union[float, int], newrangemax: Union[float, int], value: Union[float, int]) Union[float, int] ¶
This function converts the original value into a new defined value in the new range
- Parameters:
- Return int|float:
converted value