Exemplo n.º 1
0
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
Exemplo n.º 2
0
 def __init__(self, width, height, rotate, mode, transform, scale):
     super(emulator, self).__init__(serial_interface=noop())
     try:
         import pygame
     except:
         raise RuntimeError("Emulator requires pygame to be installed")
     self._pygame = pygame
     self.capabilities(width, height, rotate, mode)
     self.scale = 1 if transform == "none" else scale
     self._transform = getattr(transformer(pygame, width, height, scale),
                               "none" if scale == 1 else transform)
Exemplo n.º 3
0
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])
Exemplo n.º 4
0
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)
Exemplo n.º 5
0
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)
Exemplo n.º 6
0
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()
Exemplo n.º 7
0
def create_device(args, display_types=None):
    """
    Create and return device.

    :type args: object
    :type display_types: dict
    """
    device = None
    if display_types is None:
        display_types = get_display_types()

    if args.display in display_types.get('oled'):
        import luma.oled.device
        Device = getattr(luma.oled.device, args.display)
        Serial = getattr(make_serial(args), args.interface)
        device = Device(Serial(), **vars(args))

    elif args.display in display_types.get('lcd'):
        import luma.lcd.device
        import luma.lcd.aux
        Device = getattr(luma.lcd.device, args.display)
        spi = make_serial(args).spi()
        device = Device(spi, **vars(args))
        luma.lcd.aux.backlight(
            gpio=spi._gpio,
            gpio_LIGHT=args.gpio_backlight,
            active_low=args.backlight_active == "low").enable(True)

    elif args.display in display_types.get('led_matrix'):
        import luma.led_matrix.device
        from luma.core.serial import noop
        Device = getattr(luma.led_matrix.device, args.display)
        spi = make_serial(args, gpio=noop()).spi()
        device = Device(serial_interface=spi, **vars(args))

    elif args.display in display_types.get('emulator'):
        import luma.emulator.device
        Device = getattr(luma.emulator.device, args.display)
        device = Device(**vars(args))

    return device
Exemplo n.º 8
0
#!/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)

Exemplo n.º 9
0
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)
Exemplo n.º 10
0
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)