Simple test

Ensure your device works with this simple test.

examples/color_picker_simpletest.py
 1import time
 2import board
 3import terminalio
 4from displayio import Group, TileGrid, Bitmap, Palette
 5from adafruit_display_text import bitmap_label
 6import adafruit_touchscreen
 7from color_picker import color_picker
 8
 9
10display = board.DISPLAY
11
12# TouchScreen Configuration
13ts = adafruit_touchscreen.Touchscreen(
14    board.TOUCH_XL,
15    board.TOUCH_XR,
16    board.TOUCH_YD,
17    board.TOUCH_YU,
18    calibration=((5200, 59000), (5800, 57000)),
19    size=(display.width, display.height),
20)
21
22# Colorwheel Bitmap file
23filename = "wheel200.bmp"  # You can find this file in the examples directory in the library Github
24# Change the imagesize_used according to the bitmap file used. Colorwheel are identified
25# according to the size in pixels
26imagesize_used = 200
27my_colorpicker = color_picker.ColorPicker(
28    filename,
29    display.width // 2 - imagesize_used // 2,
30    display.height // 2 - imagesize_used // 2,
31    imagesize_used,
32)
33my_group = Group()
34my_group.append(my_colorpicker)
35
36palette = Palette(2)
37palette[0] = 0x990099
38palette[1] = 0x00FFFF
39
40bitmap = Bitmap(100, 20, 2)
41color_square = TileGrid(bitmap, pixel_shader=palette, x=display.width - 100, y=10)
42my_group.append(color_square)
43# Adding text information
44text_area = bitmap_label.Label(
45    terminalio.FONT,
46    text="Color",
47    x=display.width - 100,
48    y=35,
49)
50my_group.append(text_area)
51
52# Add my_group to the display
53display.show(my_group)
54
55p = False
56# Start the main loop
57while True:
58    p = ts.touch_point
59    if p:  # Check if colorpicker is selected
60        if my_colorpicker.contains(p):
61            color = my_colorpicker.when_selected(p, display.height)
62            palette[0] = color
63            print(f"Color Selected is: {hex(color)}")
64            text_area.text = str(hex(color))
65            time.sleep(1.5)
66
67    time.sleep(0.05)  # touch response on PyPortal is more accurate with a small delay

Wheel Maker Example

Shows how to make color wheel bitmaps

examples/color_picker_wheel_maker_simpletest.py
1from color_picker.wheel_maker import make_wheel
2
3make_wheel("wheel100.bmp", 100, 0x000000)