Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import time
- from gpiozero import PWMOutputDevice
- # LED matrix configuration:
- LED_COUNT = 128 # Number of LED pixels (2 * 8x8 matrix panels)
- LED_PIN = 12 # GPIO pin connected to the DIN pin of the matrix panel
- LED_FREQ_HZ = 200000 # LED signal frequency in hertz (usually 800kHz)
- # Color values
- BLACK = (0, 0, 0)
- RED = (255, 0, 0)
- GREEN = (0, 255, 0)
- BLUE = (0, 0, 255)
- def color_to_bits(color):
- """Convert a color tuple to bit representation."""
- red, green, blue = color
- bits = []
- for byte in (green, red, blue):
- for _ in range(8):
- bits.append(byte & 0x80)
- byte <<= 1
- return bits
- def send_bit(bit):
- """Send a single bit to the LED matrix panel."""
- led_pin.value = 1
- time.sleep(0.00000055 if bit else 0.00000028)
- led_pin.value = 0
- time.sleep(0.00000018 if bit else 0.00000058)
- def send_color(color):
- """Send a color to the LED matrix panel."""
- bits = color_to_bits(color)
- for bit in bits:
- send_bit(bit)
- time.sleep(0.00005) # Reset delay
- def colorWipe(color, wait_ms=50):
- """Wipe color across the matrix panel."""
- for i in range(LED_COUNT):
- send_color(color)
- time.sleep(wait_ms / 1000.0)
- # Main program logic follows:
- if __name__ == '__main__':
- led_pin = PWMOutputDevice(LED_PIN)
- print('Press Ctrl-C to quit.')
- try:
- while True:
- print('Color wipe animations.')
- colorWipe(RED) # Red wipe
- colorWipe(GREEN) # Green wipe
- colorWipe(BLUE) # Blue wipe
- except KeyboardInterrupt:
- colorWipe(BLACK) # Turn off all LEDs
- led_pin.close()
Advertisement
Add Comment
Please, Sign In to add comment