Puzzle Unit
Unit-Puzzle is a colorful lighting control unit, consisting of an 8x8 RGB array of 64 colorful WS2812E RGB lamp beads.
Support the following products:
Micropython Example:
1# SPDX-FileCopyrightText: 2024 M5Stack Technology CO LTD 2# 3# SPDX-License-Identifier: MIT 4 5import os, sys, io 6import M5 7from M5 import * 8from unit import PuzzleUnit 9import time 10 11 12title0 = None 13label0 = None 14label1 = None 15puzzle_0 = None 16 17 18def setup(): 19 global title0, label0, label1, puzzle_0 20 21 M5.begin() 22 Widgets.fillScreen(0x222222) 23 title0 = Widgets.Title( 24 "UnitPuzzle M5Core2 Example", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.DejaVu18 25 ) 26 label0 = Widgets.Label( 27 "Pls see the Puzzle", 76, 102, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18 28 ) 29 label1 = Widgets.Label( 30 "Program will run automatically", 10, 134, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18 31 ) 32 33 puzzle_0 = PuzzleUnit((33, 32), 1) 34 puzzle_0.set_brightness(10) 35 36 37def loop(): 38 global title0, label0, label1, puzzle_0 39 M5.update() 40 puzzle_0.set_color(1, 1, 0xFFFFFF) 41 puzzle_0.set_color(1, 64, 0x66FFFF) 42 time.sleep(1) 43 puzzle_0.fill_color(0x6600CC) 44 time.sleep(1) 45 puzzle_0.set_color_from(1, 1, 64, 0x6600CC, 0) 46 puzzle_0.set_color_from(1, 64, 1, 0x33FF33, 30) 47 time.sleep(1) 48 puzzle_0.set_color_running_from(1, 1, 64, 0x6600CC, 30) 49 puzzle_0.set_color_running_from(1, 64, 1, 0x33FF33, 30) 50 time.sleep(1) 51 puzzle_0.set_color_saturation_from(1, 1, 64, 0x6600CC, 30) 52 puzzle_0.set_color_saturation_from(1, 64, 1, 0x33FF33, 30) 53 time.sleep(1) 54 puzzle_0.set_random_color_random_led_from(1, 1, 64) 55 time.sleep(1) 56 puzzle_0.set_screen( 57 1, 58 [ 59 0xFFFFFF, 60 0xFFFFFF, 61 0, 62 0, 63 0, 64 0, 65 0xFFFFFF, 66 0xFFFFFF, 67 0xFFFFFF, 68 0xFFFFFF, 69 0xFFFFFF, 70 0, 71 0, 72 0xFFFFFF, 73 0xFFFFFF, 74 0xFFFFFF, 75 0xFFFFFF, 76 0, 77 0xFFFFFF, 78 0xFFFFFF, 79 0xFFFFFF, 80 0xFFFFFF, 81 0, 82 0xFFFFFF, 83 0xFFFFFF, 84 0, 85 0xFFFFFF, 86 0xFFFFFF, 87 0xFFFFFF, 88 0xFFFFFF, 89 0, 90 0xFFFFFF, 91 0xFFFFFF, 92 0, 93 0, 94 0xFFFFFF, 95 0xFFFFFF, 96 0, 97 0, 98 0xFFFFFF, 99 0xFFFFFF, 100 0, 101 0, 102 0, 103 0, 104 0, 105 0, 106 0xFFFFFF, 107 0xFFFFFF, 108 0, 109 0, 110 0, 111 0, 112 0, 113 0, 114 0xFFFFFF, 115 0xFFFFFF, 116 0, 117 0, 118 0, 119 0, 120 0, 121 0, 122 0xFFFFFF, 123 ], 124 ) 125 time.sleep(1) 126 127 128if __name__ == "__main__": 129 try: 130 setup() 131 while True: 132 loop() 133 except (Exception, KeyboardInterrupt) as e: 134 try: 135 from utility import print_error_msg 136 137 print_error_msg(e) 138 except ImportError: 139 print("please update to latest firmware")
UIFLOW2 Example:
class PuzzleUnit
Constructors
Methods
- PuzzleUnit.fill_color(color)
Set the entire screen or area to a specific RGB color.
- Parameters:
color (int) – The RGB color to fill the area with.
UIFLOW2:
- PuzzleUnit.set_color(index, color)
Set the color of a specific pixel or LED.
- Parameters:
index – The index of the pixel or LED to set the color on.
color (int) – The color to set, specified in RGB format.
UIFLOW2:
- PuzzleUnit.set_brightness(br)
Adjust the brightness of the LEDs based on the given percentage.
- Parameters:
br (int) – The brightness percentage (0-100).
UIFLOW2:
- PuzzleUnit.set_color_from(board_num, begin, end, rgb, per_delay)
Set color on a range of LEDs starting from a specified board and range.
- Parameters:
board_num (int) – The board number (starting from 1) where the LEDs are located.
begin (int) – The starting LED index on the board.
end (int) – The ending LED index on the board.
rgb (int) – The color to set, specified in RGB format.
per_delay (int) – Delay in milliseconds between setting each LED color.
UIFLOW2:
- PuzzleUnit.set_color(board_num, index, rgb)
Set the color of a single LED.
- Parameters:
UIFLOW2:
- PuzzleUnit.set_color_saturation_from(board_num, begin, end, rgb_color, per_delay)
Gradually change the color saturation from begin to end on a range of LEDs.
- Parameters:
board_num (int) – The board number (starting from 1) where the LEDs are located.
begin (int) – The starting LED index on the board.
end (int) – The ending LED index on the board.
rgb_color (int) – The base RGB color to apply saturation to.
per_delay (int) – Delay in milliseconds between each LED color change.
UIFLOW2:
- PuzzleUnit.set_color_running_from(board_num, begin, end, rgb, per_delay)
Create a running color effect on a range of LEDs from begin to end.
- Parameters:
board_num (int) – The board number (starting from 1) where the LEDs are located.
begin (int) – The starting LED index on the board.
end (int) – The ending LED index on the board.
rgb (int) – The color to set, specified in RGB format.
per_delay (int) – Delay in milliseconds between setting each LED color.
UIFLOW2:
- PuzzleUnit.set_random_color_random_led_from(board_num, begin, end)
Set a random color to each LED within the specified range.
- Parameters:
UIFLOW2: