示例#1
0
                             serpentine=True,
                             rgb_pins=[
                                 board.MTX_R1, board.MTX_G1, board.MTX_B1,
                                 board.MTX_R2, board.MTX_G2, board.MTX_B2
                             ],
                             addr_pins=[
                                 board.MTX_ADDRA, board.MTX_ADDRB,
                                 board.MTX_ADDRC, board.MTX_ADDRD
                             ],
                             clock_pin=board.MTX_CLK,
                             latch_pin=board.MTX_LAT,
                             output_enable_pin=board.MTX_OE)

# Associate matrix with a Display to use displayio features
DISPLAY = framebufferio.FramebufferDisplay(MATRIX,
                                           auto_refresh=False,
                                           rotation=0)

# Load BMP image, create Group and TileGrid to hold it
FILENAME = "wales.bmp"

# CircuitPython 6 & 7 compatible
BITMAP = displayio.OnDiskBitmap(open(FILENAME, "rb"))
TILEGRID = displayio.TileGrid(BITMAP,
                              pixel_shader=getattr(BITMAP, 'pixel_shader',
                                                   displayio.ColorConverter()),
                              tile_width=BITMAP.width,
                              tile_height=BITMAP.height)

# # CircuitPython 7+ compatible
# BITMAP = displayio.OnDiskBitmap(FILENAME)
import displayio
import framebufferio
import rgbmatrix
import terminalio
displayio.release_displays()

matrix = rgbmatrix.RGBMatrix(
    width=64,
    height=32,
    bit_depth=3,
    rgb_pins=[board.D6, board.D5, board.D9, board.D11, board.D10, board.D12],
    addr_pins=[board.A5, board.A4, board.A3, board.A2],
    clock_pin=board.D13,
    latch_pin=board.D0,
    output_enable_pin=board.D1)
display = framebufferio.FramebufferDisplay(matrix, auto_refresh=False)


# Create a tilegrid with a bunch of common settings
def tilegrid(palette):
    return displayio.TileGrid(bitmap=terminalio.FONT.bitmap,
                              pixel_shader=palette,
                              width=1,
                              height=1,
                              tile_width=6,
                              tile_height=14,
                              default_tile=32)


g = displayio.Group()
示例#3
0
switch_pin.direction = digitalio.Direction.INPUT
switch_pin.pull = digitalio.Pull.UP
switch = Debouncer(switch_pin)

# Initialize the LED Glasses
#
# In this example scale is set to True. When True the logical display is
# three times the physical display size and scaled down to allow text to
# look more natural for small display sizes. Hence the display is created
# as 54x15 when the physical display is 18x5.
#
i2c = busio.I2C(board.SCL, board.SDA, frequency=1000000)
is31 = is31fl3741.IS31FL3741(i2c=i2c)
is31_framebuffer = is31fl3741.IS31FL3741_FrameBuffer(
    is31, 54, 15, glassesmatrix_ledmap_no_ring, scale=True, gamma=True)
display = framebufferio.FramebufferDisplay(is31_framebuffer, auto_refresh=True)

# Set up the left and right eyelight rings
# init is set to False as the IS31FL3741_FrameBuffer has already initialized the IS31FL3741 driver
left_eye = IS31FL3741_PixelBuf(is31,
                               left_ring_map_no_inner,
                               init=False,
                               auto_write=False)
right_eye = IS31FL3741_PixelBuf(is31,
                                right_ring_map_no_inner,
                                init=False,
                                auto_write=False)

# Dim the display. Full brightness is BRIGHT
is31_framebuffer.brightness = 0.2
    "Tony McDade",
    "David McAtee",
    "George Floyd",
]

displayio.release_displays()
matrix = rgbmatrix.RGBMatrix(
    width=64,
    bit_depth=4,
    rgb_pins=[board.D6, board.D5, board.D9, board.D11, board.D10, board.D12],
    addr_pins=[board.A5, board.A4, board.A3, board.A2],
    clock_pin=board.D13,
    latch_pin=board.D0,
    output_enable_pin=board.D1,
)
display = framebufferio.FramebufferDisplay(matrix)

# Create a 3 line set of small font text
blm_font = [None, None, None]
for line in range(3):
    label = adafruit_display_text.label.Label(terminalio.FONT,
                                              color=0xFFFFFF,
                                              x=2,
                                              y=line * 10 + 5)
    blm_font[line] = label

# Create a 2 line set of font text
names_font = [None, None]
for line in range(2):
    label = adafruit_display_text.label.Label(
        terminalio.FONT,
print("Found product {}".format(seesaw_product))
if seesaw_product != 4991:
    print("Wrong firmware loaded?  Expected 4991")

button = DigitalIO(seesaw, 24)

encoder = IncrementalEncoder(seesaw)
LAST_POSITION = 0

# Set up display
bus = board.SPI()
chip_select_pin = board.IO12
framebuffer = sharpdisplay.SharpMemoryFramebuffer(bus, chip_select_pin, 400,
                                                  240)

display = framebufferio.FramebufferDisplay(framebuffer)

splash = displayio.Group()
display.show(splash)

# Set up PWM LEDs
WARM_PIN = board.IO5
COOL_PIN = board.IO6

FADE_SLEEP = 0.01  # Number of milliseconds to delay between changes.
# Increase to slow down, decrease to speed up.

# Define PWM outputs:
warm = pwmio.PWMOut(WARM_PIN)
cool = pwmio.PWMOut(COOL_PIN)
示例#6
0
    def __init__(self,
                 *,
                 width=64,
                 height=32,
                 bit_depth=2,
                 alt_addr_pins=None,
                 color_order="RGB"):

        if not isinstance(color_order, str):
            raise ValueError("color_index should be a string")
        color_order = color_order.lower()
        red_index = color_order.find("r")
        green_index = color_order.find("g")
        blue_index = color_order.find("b")
        if -1 in (red_index, green_index, blue_index):
            raise ValueError("color_order should contain R, G, and B")

        if "Matrix Portal M4" in os.uname().machine:
            # MatrixPortal M4 Board
            addr_pins = [board.MTX_ADDRA, board.MTX_ADDRB, board.MTX_ADDRC]
            if height > 16:
                addr_pins.append(board.MTX_ADDRD)
            if height > 32:
                addr_pins.append(board.MTX_ADDRE)
            rgb_pins = [
                board.MTX_R1,
                board.MTX_G1,
                board.MTX_B1,
                board.MTX_R2,
                board.MTX_G2,
                board.MTX_B2,
            ]
            clock_pin = board.MTX_CLK
            latch_pin = board.MTX_LAT
            oe_pin = board.MTX_OE
        elif "Feather" in os.uname().machine:
            # Feather Style Board
            if "nrf52" in os.uname().sysname:
                # nrf52840 Style Feather
                addr_pins = [board.D11, board.D5, board.D13]
                if height > 16:
                    addr_pins.append(board.D9)
                rgb_pins = [
                    board.D6, board.A5, board.A1, board.A0, board.A4, board.D11
                ]
                clock_pin = board.D12
            else:
                addr_pins = [board.A5, board.A4, board.A3]
                if height > 16:
                    addr_pins.append(board.A2)
                rgb_pins = [
                    board.D6,
                    board.D5,
                    board.D9,
                    board.D11,
                    board.D10,
                    board.D12,
                ]
                clock_pin = board.D13
            latch_pin = board.D0
            oe_pin = board.D1
        else:
            # Metro/Grand Central Style Board
            if alt_addr_pins is None and height <= 16:
                raise RuntimeError(
                    "Pin A2 unavailable in this mode. Please specify alt_addr_pins."
                )
            addr_pins = [board.A0, board.A1, board.A2, board.A3]
            rgb_pins = [
                board.D2, board.D3, board.D4, board.D5, board.D6, board.D7
            ]
            clock_pin = board.A4
            latch_pin = board.D10
            oe_pin = board.D9

        # Alternate Address Pins
        if alt_addr_pins is not None:
            addr_pins = alt_addr_pins

        try:
            displayio.release_displays()
            matrix = rgbmatrix.RGBMatrix(
                width=width,
                height=height,
                bit_depth=bit_depth,
                rgb_pins=(
                    rgb_pins[red_index],
                    rgb_pins[green_index],
                    rgb_pins[blue_index],
                    rgb_pins[red_index + 3],
                    rgb_pins[green_index + 3],
                    rgb_pins[blue_index + 3],
                ),
                addr_pins=addr_pins,
                clock_pin=clock_pin,
                latch_pin=latch_pin,
                output_enable_pin=oe_pin,
            )
            self.display = framebufferio.FramebufferDisplay(matrix)
        except ValueError:
            raise RuntimeError(
                "Failed to initialize RGB Matrix") from ValueError
import microcontroller
import sharpdisplay
import supervisor
import terminalio

try:
    import usb_hid
except ImportError:
    usb_hid = None

# Initialize the display, cleaning up after a display from the previous
# run if necessary
displayio.release_displays()
framebuffer = sharpdisplay.SharpMemoryFramebuffer(board.SPI(), board.RX, 400,
                                                  240)
display = framebufferio.FramebufferDisplay(framebuffer, auto_refresh=False)


def extraprec(add=8, num=0, den=1):
    def inner(fn):
        def wrapper(*args, **kw):
            with localcontext() as ctx:
                ctx.prec = ctx.prec + add + (ctx.prec * num + den - 1) // den
                result = fn(*args, **kw)
            return +result

        return wrapper

    return inner