Пример #1
0
def main():
    # Setup for Banggood version of 4 x 8x8 LED Matrix (https://bit.ly/2Gywazb)
    serial = spi(port=0, device=0, gpio=noop())
    device = max7219(serial, cascaded=4, block_orientation=-90, blocks_arranged_in_reverse_order=True)
    device.contrast(16)

    # The time ascends from the abyss...
    animation(device, 8, 1)

    toggle = False  # Toggle the second indicator every second
    while True:
        toggle = not toggle
        sec = datetime.now().second
        if sec == 59:
            # When we change minutes, animate the minute change
            minute_change(device)
        elif sec == 30:
            # Half-way through each minute, display the complete date/time,
            # animating the time display into and out of the abyss.
            full_msg = time.ctime()
            animation(device, 1, 8)
            show_message(device, full_msg, fill="white", font=proportional(CP437_FONT))
            animation(device, 8, 1)
        else:
            # Do the following twice a second (so the seconds' indicator blips).
            # I'd optimize if I had to - but what's the point?
            # Even my Raspberry PI2 can do this at 4% of a single one of the 4 cores!
            hours = datetime.now().strftime('%H')
            minutes = datetime.now().strftime('%M')
            with canvas(device) as draw:
                text(draw, (0, 1), hours, fill="white", font=proportional(CP437_FONT))
                text(draw, (15, 1), ":" if toggle else " ", fill="white", font=proportional(TINY_FONT))
                text(draw, (17, 1), minutes, fill="white", font=proportional(CP437_FONT))
            time.sleep(0.5)
Пример #2
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)
Пример #3
0
def animation(device, from_y, to_y):
    '''Animate the whole thing, moving it into/out of the abyss.'''
    hourstime = datetime.now().strftime('%H')
    mintime = datetime.now().strftime('%M')
    current_y = from_y
    while current_y != to_y:
        with canvas(device) as draw:
            text(draw, (0, current_y), hourstime, fill="white", font=proportional(CP437_FONT))
            text(draw, (15, current_y), ":", fill="white", font=proportional(TINY_FONT))
            text(draw, (17, current_y), mintime, fill="white", font=proportional(CP437_FONT))
        time.sleep(0.1)
        current_y += 1 if to_y > from_y else -1
Пример #4
0
def main():
    msg = "Neopixel WS2812 LED Matrix Demo"
    show_message(device, msg, y_offset=-1, fill="green", font=proportional(TINY_FONT))
    time.sleep(1)

    with canvas(device) as draw:
        text(draw, (0, -1), txt="A", fill="red", font=TINY_FONT)
        text(draw, (4, -1), txt="T", fill="green", font=TINY_FONT)

    time.sleep(1)

    with canvas(device) as draw:
        draw.line((0, 0, 0, device.height), fill="red")
        draw.line((1, 0, 1, device.height), fill="orange")
        draw.line((2, 0, 2, device.height), fill="yellow")
        draw.line((3, 0, 3, device.height), fill="green")
        draw.line((4, 0, 4, device.height), fill="blue")
        draw.line((5, 0, 5, device.height), fill="indigo")
        draw.line((6, 0, 6, device.height), fill="violet")
        draw.line((7, 0, 7, device.height), fill="white")

    time.sleep(4)

    for _ in range(5):
        for intensity in range(16):
            device.contrast(intensity * 16)
            time.sleep(0.1)

    device.contrast(0x80)
    time.sleep(1)

    gfx(device)
Пример #5
0
def display_code():
    global displaying_code, prev_time_of_day
    prev_time_of_day = '99:99'

    if displaying_code:
        return

    if display_mode == 'static':
        with canvas(device) as draw:
            text(draw, (6, 0), code, fill="white", font=proportional(LCD_FONT))
    else:
        show_message(device,
                     code,
                     fill="white",
                     font=proportional(LCD_FONT),
                     scroll_delay=0.1)

    displaying_code = True
Пример #6
0
def mostrar_mensaje(msg, delay=0.5, font=1):
    '''
        Muestra el mensaje en la matriz
    '''
    show_message(device,
                 msg,
                 fill="white",
                 font=proportional(font[font]),
                 scroll_delay=delay)
Пример #7
0
def scroller():
    # create matrix device
    serial = spi(port=0, device=0, gpio=noop())
    device = max7219(serial, cascaded=4, block_orientation=-90, rotate=0)

    # start demo
    msg = "NOW PLAYING: "
    show_message(device, msg, fill="white", font=proportional(CP437_FONT))
    time.sleep(1)
Пример #8
0
 def __init__(self, numberOfBlocks, font=proportional(TINY_FONT)):
     self.device = max7219(
         self.serial,
         width=32 * numberOfBlocks,
         hight=8,
         block_orientation=-90
     )  #,blocks_arranged_in_reverse_order="inreverse")
     self.textList = [''] * numberOfBlocks
     self.font = font
Пример #9
0
	def update_display(self):

		if self.type_received:
			if self.type_val == "customer":
				if self.sensor_received:
					with canvas(self.virtual) as draw:
						text(draw, (1, 1), "{}".format(self.sensor_val), 
							fill="white", font=proportional(CP437_FONT))
						rospy.sleep(1)
			elif self.type_val == "store":
				if self.box_received:
					with canvas(self.virtual) as draw:
						text(draw, (1, 1), "{}".format(self.box), 
							fill="white", font=proportional(CP437_FONT))
						rospy.sleep(1)
		else:
			with canvas(self.virtual) as draw:
				text(draw, (1, 1), "SCAN", fill="white", font=proportional(CP437_FONT))
 def _show_msg(self):
     while True:  # forever
         show_message(
             self.device,
             self.msg,
             fill="white",
             font=proportional(LCD_FONT),
             scroll_delay=0.05,
         )  # display the scrolling message
def emoji(msg):
    device = max7219(serial, cascaded=1, block_orientation=0, rotate=1)
    time.sleep(0.1)
    show_message(device,
                 msg,
                 fill="white",
                 font=proportional(LCD_FONT),
                 scroll_delay=0.2)
    device = max7219(serial, cascaded=1, block_orientation=0, rotate=0)
Пример #12
0
 def show_text(self, text):
     try:
         show_message(self._device,
                      text,
                      fill="white",
                      font=proportional(CP437_FONT))
     except IndexError:
         print "[Max7219Scroller] Error showing text: " + AsciiFormatter(
         ).format(text)
Пример #13
0
 def showMessage(self, textString, sleepTime=0.1):
     print(self.device.width)
     #self.device.width
     for i in range((len(textString) * 6)):
         with canvas(self.device) as draw:
             text(draw, (i * -1, 0),
                  textString,
                  fill="white",
                  font=proportional(LCD_FONT))
         time.sleep(sleepTime)
Пример #14
0
def demo(str):
    # create matrix device
    serial = spi(port=0, device=0, gpio=noop())
    device = max7219(serial, cascaded=4, block_orientation=-90, rotate=0)

    print("Created device")

    with canvas(device) as draw:
        text(draw, (3, 0), str, fill="white", font=proportional(LCD_FONT))
    time.sleep(300)
def renderDisplay():
    while 1:
        global device
        device.contrast(dc.brightness)
        print(dc.text)
        show_message(device,
                     dc.text,
                     fill="white",
                     font=proportional(LCD_FONT),
                     scroll_delay=dc.speed)
Пример #16
0
def set_text():
    global deviceViewport

    text = request.args.get('msg')
    fontName = parse_font_name(request.args.get('font'))
    font = proportional(fontName) if request.args.get(
        'proportional') else tolerant(fontName)
    set_contentHotspot(textSnapshot(text=text, font=font), (32, 0))

    return 'OK'
Пример #17
0
 def do_POST(self):
     content_length = int(self.headers['Content-Length'])
     post_data = self.rfile.read(content_length)
     self._set_headers()
     if self.path == '/led':
         show_message(device,
                      post_data,
                      fill="white",
                      font=proportional(LCD_FONT),
                      scroll_delay=0.03)
Пример #18
0
    def update_display(self):
        self.getSensor()

        if self.sensor.data != self.sensor_val:
            show_message(self.device,
                         'Box: {}'.format(self.sensor.data),
                         fill="white",
                         font=proportional(LCD_FONT),
                         scroll_delay=0.08)

            with canvas(self.virtual) as draw:
                text(draw, (1, 1),
                     "Box:{}".format(self.sensor.data),
                     fill="white",
                     font=proportional(LCD_FONT))

            self.sensor_val = self.sensor.data
        else:
            pass
Пример #19
0
def jprint(obj, error, error_name):
    if error:
        print("Error: " + str(error_name) + "...")
        show_message(device,
                     "Error: " + str(error_name) + "...",
                     fill="white",
                     font=proportional(LCD_FONT),
                     scroll_delay=0.08)
    text = json.dumps(obj, sort_keys=True, indent=4)
    # print(text)
    weather_json = json.loads(text)
    #print(weather_json['current'])
    current_json = weather_json['current']  #Get current info
    temp = current_json['temperature']  #Get current Temparature
    #print("Temparature "+str(temp)+"oC")
    show_message(device,
                 "Temparature " + str(temp) + "oC",
                 fill="white",
                 font=proportional(LCD_FONT),
                 scroll_delay=0.08)
    humidity = current_json['humidity']
    #print("Humidity "+str(humidity)+"%") #Get current Humidity
    show_message(device,
                 "Humidity " + str(humidity) + "%",
                 fill="white",
                 font=proportional(LCD_FONT),
                 scroll_delay=0.08)
    real_feel = current_json['feelslike']
    #print("Real feel "+str(real_feel)+"oC") #Get real feeling
    show_message(device,
                 "Real feel " + str(real_feel) + "oC",
                 fill="white",
                 font=proportional(LCD_FONT),
                 scroll_delay=0.08)
    weather_descript = current_json['weather_descriptions']
    for w in range(len(weather_descript)):
        #print("Weather descriptions "+weather_descript[w]) #Weather Descriptions
        show_message(device,
                     weather_descript[w],
                     fill="white",
                     font=proportional(LCD_FONT),
                     scroll_delay=0.08)
Пример #20
0
    def dibujar_vertical(self):
        words = ["Victor", "Echo", "Romeo"]

        virtual = viewport(self.device, width=self.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 - self.device.height):
            virtual.set_position((0, i))
            time.sleep(0.05)
Пример #21
0
def Clock(n, block_orientation, rotate):
    serial = spi(port=0, device=0, gpio=noop())
    device = max7219(serial, cascaded=8, block_orientation=-90, rotate=rotate)
    if ((now.hour + 1) < 9 or (now.hour + 1) > 19):
        device.contrast(1)
        print("Kisebb fényerő")
    print("Óra")
    msg = ora + " : " + perc + "      " + ora + " : " + perc
    print(msg)
    show_message(device, msg, fill="white", font=proportional(CP437_FONT))
    time.sleep(1)
Пример #22
0
def LEDMatrix(cascaded, block_orientation, rotate, msg):
    # create matrix device
    serial = spi(port=0, device=1, gpio=noop())
    device = max7219(serial, cascaded=cascaded or 1, block_orientation=block_orientation, rotate=rotate or 0)
    # debugging purpose
    print("[-] Matrix initialized")

    # debugging purpose
    print("[-] Printing: %s" % msg)
    show_message(device, msg, fill="white", font=proportional(CP437_FONT), scroll_delay=0.1)
    GPIO.cleanup()
def set_matrix(number):

    number = str(number)

    with canvas(device) as draw:
        legacy.text(draw, (0, 0),
                    "Your string here",
                    fill="white",
                    font=proportional(CP437_FONT))

    return None
Пример #24
0
def Cpu(n, block_orientation, rotate):
    serial = spi(port=0, device=0, gpio=noop())
    device = max7219(serial, cascaded=8, block_orientation=-90, rotate=rotate)
    if ((now.hour + 1) < 9 or (now.hour + 1) > 19):
        device.contrast(1)
        print("Kisebb fényerő")
    print("CPU Hofok")
    msg = "CPU hofok: " + str(cel) + " C"
    print(msg)
    show_message(device, msg, fill="white", font=proportional(CP437_FONT))
    time.sleep(1)
Пример #25
0
def loop(
    n,
    block_orientation,
    rotate,
    inreverse,
    time_format="%H:%M",
    no_zero=True,
    font=font,
):
    print("Initializing device")
    # create matrix device
    serial = spi(port=0, device=0, gpio=noop())
    device = max7219(
        serial,
        cascaded=n or 1,
        block_orientation=block_orientation,
        rotate=rotate or 0,
        blocks_arranged_in_reverse_order=inreverse,
    )

    print("Starting infinite loop")
    while True:
        now = datetime.datetime.now()
        msg_time = now.strftime(time_format)

        # convert first zero to space, notice that %-H produces hours without spaces
        if no_zero and (msg_time[0] == "0"):
            msg = " " + msg_time[1:]
        else:
            msg = msg_time

        # draw each letter separately, to allow to have colon sign
        # still, hours are more squeezed than minutes for readibility
        with canvas(device) as draw:
            text(draw, (0, 0), msg[0], fill="white", font=proportional(font))
            text(draw, (3, 0), msg[1], fill="white", font=proportional(font))
            text(draw, (7, 0), msg[2], fill="white", font=proportional(font))
            text(draw, (9, 0), msg[3], fill="white", font=proportional(font))
            text(draw, (13, 0), msg[4], fill="white", font=proportional(font))
        device.contrast(contrast)
        time.sleep(1)
Пример #26
0
def matrix():

    serial = spi(port=0, device=0, gpio=noop())
    scoreboard = max7219(serial, cascaded=4, block_orientation=-90, rotate=2)
    virtual = viewport(scoreboard, width=200, height=8)
    scoreboard.contrast(20)
    with canvas(virtual) as draw:
        text(draw, (0, 0),
             "        BOGY 2019 - Mitutoyo CTL",
             fill="white",
             font=proportional(LCD_FONT))
    return virtual
Пример #27
0
def Idojaras(n, block_orientation, rotate):
    serial = spi(port=0, device=0, gpio=noop())
    device = max7219(serial, cascaded=8, block_orientation=-90, rotate=rotate)
    idojaras_lekerese(API)
    if ((now.hour + 1) < 9 or (now.hour + 1) > 19):
        device.contrast(1)
        print("Kisebb fényerő")
    print("Idojaras")
    msg = "Kinti homerseklet: " + str(jelenlegi_idojaras) + "C Szelsebesseg: " + str(szelsebesseg) + "km/h"
    print(msg)
    show_message(device, msg, fill="white", font=proportional(CP437_FONT))
    time.sleep(1)
Пример #28
0
def demo(n, block_orientation, rotate):
    # create matrix device
    serial = spi(port=0, device=0, gpio=noop())
    device = max7219(serial,
                     cascaded=n or 1,
                     block_orientation=block_orientation,
                     rotate=rotate or 0)
    Humidity, Celsius = Adafruit_DHT.read_retry(11, 4)
    Fahrenheit = 9.0 / 5.0 * Celsius + 32
    print json.dumps({'temp': Fahrenheit, 'humidity': Humidity})
    msg = 'Temp: {0:0.1f} F  Humidity: {1:0.1f} %'.format(Fahrenheit, Humidity)
    show_message(device, msg, fill="white", font=proportional(LCD_FONT))
Пример #29
0
def scrollText(text):
    if PI:
        show_message(MAX2719device,
                     text,
                     fill="white",
                     font=proportional(CP437_FONT))
        #MAX2719device.show_message(text, font=proportional(CP437_FONT))
    else:
        titleSurf, titleRect = makeTextObjs(str(text), BASICFONT, TEXTCOLOR)
        titleRect.center = (int(WINDOWWIDTH / 2) - 3,
                            int(WINDOWHEIGHT / 2) - 3)
        DISPLAYSURF.blit(titleSurf, titleRect)
Пример #30
0
def Nevnap(n, block_orientation, rotate):
    serial = spi(port=0, device=0, gpio=noop())
    device = max7219(serial, cascaded=8, block_orientation=-90, rotate=rotate)
    nevnap_kinyerese(month, day)
    print("nameday")
    if ((now.hour + 1) < 5 or (now.hour + 1) > 19):
        device.contrast(1)
        print("Kisebb fényerő")
    msg = "Mai nevnap: " + str(mai_nevnap)
    print(msg)
    show_message(device, msg, fill="white", font=proportional(CP437_FONT))
    time.sleep(1)
Пример #31
0
def animation(device, from_y, to_y):
    '''Animate the whole thing, moving it into/out of the abyss.'''
    hourstime = datetime.now().strftime('%H')
    mintime = datetime.now().strftime('%M')
    current_y = from_y
    while current_y != to_y:
        with canvas(device) as draw:
            text(draw, (0, current_y),
                 hourstime,
                 fill="white",
                 font=proportional(TINY_FONT))
            text(draw, (15, current_y),
                 ":",
                 fill="white",
                 font=proportional(TINY_FONT))
            text(draw, (17, current_y),
                 mintime,
                 fill="white",
                 font=proportional(TINY_FONT))
        time.sleep(0.1)
        current_y += 1 if to_y > from_y else -1
Пример #32
0
def main(num_iterations=4):
    device = get_device()

    while num_iterations > 0:
        num_iterations -= 1

        msg = "a"
        show_message(device,
                     msg,
                     fill="white",
                     font=proportional(SINCLAIR_FONT))
        time.sleep(1)
Пример #33
0
def show_vertical_message(device):
    words = ["Hello", "IOT", "World!", " "]
    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(SINCLAIR_FONT))
    for i in range(virtual.height - device.height):
        virtual.set_position((0, i))
        time.sleep(0.20)
Пример #34
0
 def message(self, msg):
     """
     Display the message (one by one) with a delay-rate of 4 on the one-char-display
     :param msg: Message to show
     """
     if FakeIO:
         logger.info("Message:" + msg)
     else:
         show_message(self.device,
                      msg,
                      fill="white",
                      font=proportional(CP437_FONT),
                      scroll_delay=4)
Пример #35
0
def displayScroll(msg):
    # print(msg)
    show_message(device, msg, fill="white",
                 font=proportional(LCD_FONT), scroll_delay=0.03)
Пример #36
0
import re
import time
import argparse

from luma.led_matrix.device import max7219
from luma.core.interface.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

# create matrix device
serial = spi(port=0, device=0, gpio=noop())
device = max7219(serial, cascaded=4, block_orientation=-90)
print("Created device")

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)
Пример #37
0
def demo(n, block_orientation, rotate, inreverse):
    # create matrix device
    serial = spi(port=0, device=0, gpio=noop())
    device = max7219(serial, cascaded=n or 1, block_orientation=block_orientation,
                     rotate=rotate or 0, blocks_arranged_in_reverse_order=inreverse)
    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)
Пример #38
0
 def show_text_message(self,data):
      msg = data.data
      print(msg)
      show_message(self.device, msg, fill="white", font=proportional(LCD_FONT), scroll_delay=0.1)
Пример #39
0
def displayStatic(msg):
    # print(msg)
    with canvas(device) as draw:
        text(draw, (1, 0), msg, fill="white", font=proportional(LCD_FONT))
Пример #40
0
 def helper(current_y):
     with canvas(device) as draw:
         text(draw, (0, 1), hours, fill="white", font=proportional(CP437_FONT))
         text(draw, (15, 1), ":", fill="white", font=proportional(TINY_FONT))
         text(draw, (17, current_y), minutes, fill="white", font=proportional(CP437_FONT))
     time.sleep(0.1)