Ejemplo n.º 1
0
def show(matrix, image, dx=0, dy=0):
    ''' show(matrix, image, dx=0, dy=0)'''
    for y, row in enumerate(image):
        bit = 1
        for x in range(8):
            matrix.pixel(dx + x, dy + y, row & bit)
            bit <<= 1
    matrix.show()
Ejemplo n.º 2
0
def play(frames=f, delay=.05, tf=id):
  for f in frames:
    for y, row in enumerate(f):
      for x, mask in enumerate(xMask):
        pixel = row & mask == mask
        xPx, yPx, pixel = tf(x, y, pixel)
        if pixel:
          matrix.pixel(xPx, yPx, 1)
        else:
          matrix.pixel(xPx, yPx, 0)
  matrix.show()
  time.sleep(delay)
Ejemplo n.º 3
0
def play(frames=f, delay=.05, rotate=standard):
    for frame in frames:
        for y, row in enumerate(frame):
            for x, mask in enumerate(xMask):
                pixel = row & mask == mask
                xPix, yPix, pixel = rotate(x, y, pixel)
                if pixel:
                    matrix.pixel(xPix, yPix, 1)
                else:
                    matrix.pixel(xPix, yPix, 0)
    matrix.show()
    time.sleep(delay)
Ejemplo n.º 4
0
     [0, 0, 0, 1, 1, 0, 0, 0], [1, 0, 1, 1, 1, 1, 0, 1],
     [1, 1, 1, 0, 0, 1, 1, 1], [1, 1, 0, 1, 1, 0, 1, 1],
     [1, 1, 1, 0, 0, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1]],
]

#
# run until we are out of animation frames
# use Gemma's built-in reset button or switch to restart
#
# populate matrix
while True:

    if frame_count < len(animation) and rep_count >= 0:
        for x in range(x_pix):
            for y in range(y_pix):
                matrix.pixel(x, y, animation[frame_count][x][y])

        # next animation frame
        frame_count += 1

        # show animation
        matrix.show()

        # pause for effect
        time.sleep(frame_delay[frame_count])

    else:

        matrix.fill(0)
        matrix.show()
        time.sleep(.1)
# Import the HT16K33 LED matrix module.
from adafruit_ht16k33 import matrix


# Create the I2C interface.
i2c = busio.I2C(SCL, SDA)

# Create the matrix class.
# This creates a 16x8 matrix:
matrix = matrix.Matrix16x8(i2c)
# Or this creates a 8x8 matrix:
#matrix = matrix.Matrix8x8(i2c)
# Or this creates a 8x8 bicolor matrix:
#matrix = matrix.Matrix8x8x2(i2c)
# Finally you can optionally specify a custom I2C address of the HT16k33 like:
#matrix = matrix.Matrix16x8(i2c, address=0x70)

# Clear the matrix.  Always call show after changing pixels to make the display
# update visible!
matrix.fill(0)
matrix.show()

# Set a pixel in the origin 0,0 position.
matrix.pixel(0, 0, 1)
# Set a pixel in the middle 8, 4 position.
matrix.pixel(8, 4, 1)
# Set a pixel in the opposite 15, 7 position.
matrix.pixel(15, 7, 1)
matrix.show()