import machine
import neopixel
# LED strip configuration
LED_PIN = 2
LED_COUNT = 50 # Total number of LEDs in the strip
LED_ORDER = (1, 0, 2) # Color order (GRB)
# Initialize the LED strip
led_strip = neopixel.NeoPixel(machine.Pin(LED_PIN), LED_COUNT, pixel_order=LED_ORDER)
# Game board configuration
BOARD_WIDTH = 5
BOARD_HEIGHT = 10
BOARD_PIXELS = BOARD_WIDTH * BOARD_HEIGHT
# Map the LED strip pixels to the game board grid
BOARD_START_PIXEL = (LED_COUNT - BOARD_PIXELS) // 2
BOARD_PIXEL_WIDTH = BOARD_WIDTH
BOARD_PIXEL_HEIGHT = BOARD_HEIGHT // 8
def clear_board():
for i in range(BOARD_START_PIXEL, BOARD_START_PIXEL + BOARD_PIXELS):
led_strip[i] = (0, 0, 0)
def render_block(x, y, block_color):
for i in range(BOARD_PIXEL_HEIGHT):
for j in range(BOARD_PIXEL_WIDTH):
if block_color[i][j] == 1:
led_strip[BOARD_START_PIXEL + (y * BOARD_PIXEL_HEIGHT) + i + (x * BOARD_PIXEL_WIDTH * BOARD_PIXEL_HEIGHT)] = (255, 0, 0)
# Example usage
clear_board()
render_block(2, 3, [[1, 1, 1, 1], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]])
led_strip.write()