|
| 1 | +#!/usr/bin/env python3 |
| 2 | +# Write an 8x8 Red/Green LED matrix |
| 3 | +# https://www.adafruit.com/product/902 |
| 4 | + |
| 5 | +import smbus |
| 6 | +import time |
| 7 | +bus = smbus.SMBus(1) |
| 8 | +matrix = 0x70 |
| 9 | + |
| 10 | +delay = 1; # Delay between images in s |
| 11 | + |
| 12 | +bus.write_byte_data(matrix, 0x21, 0) # Start oscillator (p10) |
| 13 | +bus.write_byte_data(matrix, 0x81, 0) # Disp on, blink off (p11) |
| 14 | +bus.write_byte_data(matrix, 0xe7, 0) # Full brightness (page 15) |
| 15 | + |
| 16 | +# The first byte is GREEN, the second is RED. |
| 17 | +smile = [0x00, 0x3c, 0x00, 0x42, 0x28, 0x89, 0x04, 0x85, |
| 18 | + 0x04, 0x85, 0x28, 0x89, 0x00, 0x42, 0x00, 0x3c |
| 19 | +] |
| 20 | +frown = [0x3c, 0x00, 0x42, 0x00, 0x85, 0x20, 0x89, 0x00, |
| 21 | + 0x89, 0x00, 0x85, 0x20, 0x42, 0x00, 0x3c, 0x00 |
| 22 | +] |
| 23 | +neutral = [0x3c, 0x3c, 0x42, 0x42, 0xa9, 0xa9, 0x89, 0x89, |
| 24 | + 0x89, 0x89, 0xa9, 0xa9, 0x42, 0x42, 0x3c, 0x3c |
| 25 | +] |
| 26 | + |
| 27 | +bus.write_i2c_block_data(matrix, 0, frown) |
| 28 | +for fade in range(0xef, 0xe0, -1): |
| 29 | + bus.write_byte_data(matrix, fade, 0) |
| 30 | + time.sleep(delay/10) |
| 31 | + |
| 32 | +bus.write_i2c_block_data(matrix, 0, neutral) |
| 33 | +for fade in range(0xe0, 0xef, 1): |
| 34 | + bus.write_byte_data(matrix, fade, 0) |
| 35 | + time.sleep(delay/10) |
| 36 | + |
| 37 | +bus.write_i2c_block_data(matrix, 0, smile) |
0 commit comments