def demo(w, h, block_orientation, rotate): # create matrix device serial = spi(port=0, device=0, gpio=noop()) device = max7219(serial, width=w, height=h, rotate=rotate, block_orientation=block_orientation) print("Created device") while (1): count = 0 while (count < 2000): with canvas(device) as draw: #draw.rectangle(device.bounding_box, outline="white") text(draw, (1, 1), "0", fill="white", font=proportional(LCD_FONT)) #time.sleep(100) count = count + 2 while (count > 0): with canvas(device) as draw: text(draw, (1, 1), "__", fill="white", font=proportional(LCD_FONT)) count = count - 100
def __init__(self, hw="spi", port=None, address=0, debug=False, buffering=True, **kwargs): if hw == "spi": if port is None: port = 0 self.serial = spi(port=port, device=address, bcm_DC=6, bcm_RST=5) elif hw == "i2c": if port is None: port = 1 if isinstance(address, basestring): address = int(address, 16) self.serial = i2c(port=port, address=address) else: raise ValueError("Unknown interface type: {}".format(hw)) self.address = address self.busy_flag = Event() self.width = 128 self.height = 64 self.charwidth = 6 self.charheight = 8 self.cols = self.width / self.charwidth self.rows = self.height / self.charheight self.debug = debug self.init_display(**kwargs) BacklightManager.init_backlight(self, **kwargs)
def main(): # create matrix device serial = spi(port=0, device=0, gpio=noop()) device = max7219(serial, cascaded=4, block_orientation=-90, rotate=2, mode="1") device.contrast(0) log_config = {"level": "INFO"} logging.basicConfig(**log_config) loop(device, [show_greetings, show_weather, show_time, show_date])
def demo(w, h, block_orientation, rotate): # create matrix device serial = spi(port=0, device=0, gpio=noop()) device = max7219(serial, width=w, height=h, rotate=rotate, block_orientation=block_orientation) print("Created device") with canvas(device) as draw: draw.rectangle(device.bounding_box, outline="white") text(draw, (2, 2), "Hello", fill="white", font=proportional(LCD_FONT)) text(draw, (2, 10), "World", fill="white", font=proportional(LCD_FONT)) time.sleep(300)
def main(): # create seven segment device serial = spi(port=0, device=0, gpio=noop()) device = max7219(serial, cascaded=1) seg = sevensegment(device) print('Simple text...') for _ in range(8): seg.text = "HELLO" time.sleep(0.6) seg.text = " GOODBYE" time.sleep(0.6) # Digit slicing print("Digit slicing") seg.text = "_" * seg.device.width time.sleep(1.0) for i, ch in enumerate([9, 8, 7, 6, 5, 4, 3, 2]): seg.text[i] = str(ch) time.sleep(0.6) for i in range(len(seg.text)): del seg.text[0] time.sleep(0.6) # Scrolling Alphabet Text print('Scrolling alphabet text...') show_message_vp(device, "HELLO EVERYONE!") show_message_vp(device, "PI is 3.14159 ... ") show_message_vp(device, "IP is 127.0.0.1 ... ") show_message_alt( seg, "0123456789 abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ") # Digit futzing date(seg) time.sleep(5) clock(seg, seconds=10) # Brightness print('Brightness...') for x in range(5): for intensity in range(16): seg.device.contrast(intensity * 16) time.sleep(0.1) device.contrast(0x7F)
def demo(n, block_orientation): # create matrix device serial = spi(port=0, device=0, gpio=noop()) device = max7219(serial, cascaded=n or 1, block_orientation=block_orientation, rotate=2) device.contrast(0) while True: now = time.localtime() with canvas(device) as draw: text(draw, (0,0), "{:02}:{:02}".format(now.tm_hour, now.tm_min), fill="white", font=proportional(CP437_FONT)) if now.tm_hour < 6 or now.tm_hour > 22: device.hide() device.clear() sleep(60*(60 - now.tm_min)) device.show()
import random from ppretty import ppretty from operator import itemgetter from luma.core.serial import spi from luma.core.render import canvas from luma.core.sprite_system import framerate_regulator from luma.lcd.device import st7735 from utils import get_device #device settings serial = spi(port=0, device=0, gpio_DC=23, gpio_RST=24, bus_speed_hz=16000000, ) device = st7735(serial) device.capabilities(width=128, height=128, rotate=0, mode='RGB') # device.width = 128 # device.height = 128 # device.size = (128, 128) # device.bounding_box = (0, 0, 159, 127) # device.framebuffer.bounding_box = (0, 0, 159, 127) # device.framebuffer.image.im.size = (160, 128) # device.framebuffer.image.size = (160, 128) # device.framebuffer.image.width = 160
import CHIP_IO.GPIO from luma.core.serial import spi from luma.oled.device import ssd1306 #Replace device = cmdline.create_device(args) with serial = spi(port=32766, device=0, gpio=CHIP_IO.GPIO, bcm_DC=“CSID1”, bcm_RST=“CSID0”) device = ssd1306(serial)
#!/usr/bin/env python import time import MakeLumaFont from luma.led_matrix.device import max7219 from luma.core.serial import spi, noop from luma.core.render import canvas from luma.core.virtual import viewport from luma.core.legacy import text, show_message from luma.core.legacy.font import proportional, CP437_FONT, TINY_FONT, SINCLAIR_FONT, LCD_FONT myFontObj=MakeLumaFont.MakeLumaFont() myFont=myFontObj.main() serial = spi(port=0, device=0, gpio=noop()) device = max7219(serial, cascaded=4, block_orientation=-90) msg='UTF-8の漢字も表示できます' for i in range(0,10): show_message(device, msg, fill="white", font=proportional(myFont)) time.sleep(1) print(msg)
def demo(n, block_orientation): # create matrix device serial = spi(port=0, device=0, gpio=noop()) device = max7219(serial, cascaded=n or 1, block_orientation=block_orientation) print("Created device") # start demo msg = "MAX7219 LED Matrix Demo" print(msg) show_message(device, msg, fill="white", font=proportional(CP437_FONT)) time.sleep(1) msg = "Fast scrolling: Lorem ipsum dolor sit amet, consectetur adipiscing\ elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut\ enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut\ aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in\ voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint\ occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit\ anim id est laborum." msg = re.sub(" +", " ", msg) print(msg) show_message(device, msg, fill="white", font=proportional(LCD_FONT), scroll_delay=0) msg = "Slow scrolling: The quick brown fox jumps over the lazy dog" print(msg) show_message(device, msg, fill="white", font=proportional(LCD_FONT), scroll_delay=0.1) print("Vertical scrolling") words = [ "Victor", "Echo", "Romeo", "Tango", "India", "Charlie", "Alpha", "Lima", " ", "Sierra", "Charlie", "Romeo", "Oscar", "Lima", "Lima", "India", "November", "Golf", " " ] virtual = viewport(device, width=device.width, height=len(words) * 8) with canvas(virtual) as draw: for i, word in enumerate(words): text(draw, (0, i * 8), word, fill="white", font=proportional(CP437_FONT)) for i in range(virtual.height - device.height): virtual.set_position((0, i)) time.sleep(0.05) msg = "Brightness" print(msg) show_message(device, msg, fill="white") time.sleep(1) with canvas(device) as draw: text(draw, (0, 0), "A", fill="white") time.sleep(1) for _ in range(5): for intensity in range(16): device.contrast(intensity * 16) time.sleep(0.1) device.contrast(0x80) time.sleep(1) msg = "Alternative font!" print(msg) show_message(device, msg, fill="white", font=SINCLAIR_FONT) time.sleep(1) msg = "Proportional font - characters are squeezed together!" print(msg) show_message(device, msg, fill="white", font=proportional(SINCLAIR_FONT)) # http://www.squaregear.net/fonts/tiny.shtml time.sleep(1) msg = "Tiny is, I believe, the smallest possible font \ (in pixel size). It stands at a lofty four pixels \ tall (five if you count descenders), yet it still \ contains all the printable ASCII characters." msg = re.sub(" +", " ", msg) print(msg) show_message(device, msg, fill="white", font=proportional(TINY_FONT)) time.sleep(1) msg = "CP437 Characters" print(msg) show_message(device, msg) time.sleep(1) for x in range(256): with canvas(device) as draw: text(draw, (0, 0), chr(x), fill="white") time.sleep(0.1)
def test(): serial = spi(port=0, device=0, gpio=noop()) device = max7219(serial, cascaded=2, block_orientation=90) print("Device created") print("W:" + str(device.width) + " H:" + str(device.height)) virtual = viewport(device, width=16, height=8) global CURRENT_PIECE global CURRENT_PIECE_INDEX global right, left, rot thread.start_new_thread(read_input, ()) while True: line = -4 piece = random.randint(0, 3) CURRENT_PIECE = PIECES[piece][:] CURRENT_PIECE_INDEX = piece while draw_piece(virtual, piece, line): if right == False: move_right(line) right = True if rot == False: rotate(line) rot = True if left == False: move_left(line) left = True line += 1 """ #print zip(*lines_matrix[::-1]) while draw_piece(virtual, 0, line): if line == 3: move_left() move_right() move_right() #move_right() #move_right() if line == 4: rotate() move_right() if line == 5: #print "Moves: " + str(MOVES_TRACE) rotate() rotate() rotate() line += 1 for p in SCREEN: print p line = -3 CURRENT_PIECE = PIECES[0][:] while draw_piece(virtual, 0, line): line += 1 for p in SCREEN: print p line = -3 CURRENT_PIECE = PIECES[1][:] while draw_piece(virtual, 1, line): line += 1 for p in SCREEN: print p line = -3 CURRENT_PIECE = PIECES[2][:] while draw_piece(virtual, 2, line): line += 1 for p in SCREEN: print p """ print("End draw") time.sleep(1)