def drawMatrix(matrix):

    gamma = 1.5
    MDP_HEIGHT = 6

    mdp.clear()

    for x in range(len(matrix)):
        buf_x = x + ((x / 5) * 3)

        for y in xrange(7):
            if matrix[x] > pow(gamma, y):
                mdp.set_pixel(buf_x, MDP_HEIGHT - y, 1)
            else:
                break

    mdp.show()
Example #2
0
def display_strings_array(lines):
    delay = 0.03

    line_height = microdotphat.HEIGHT + 2

    lengths = [0] * len(lines)

    offset_left = 0

    for line, text in enumerate(lines):
        lengths[line] = microdotphat.write_string(text,
                                                  offset_x=offset_left,
                                                  offset_y=line_height * line,
                                                  kerning=False)
        offset_left += lengths[line]

    microdotphat.set_pixel(0, (len(lines) * line_height) - 1, 0)

    current_line = 0

    microdotphat.show()

    pos_x = 0
    pos_y = 0
    for current_line in range(len(lines)):
        time.sleep(delay * 10)
        for y in range(lengths[current_line]):
            microdotphat.scroll(1, 0)
            pos_x += 1
            time.sleep(delay)
            microdotphat.show()
        if current_line == len(lines) - 1:
            microdotphat.scroll_to(0, 0)
        else:
            for x in range(line_height):
                microdotphat.scroll(0, 1)
                pos_y += 1
                microdotphat.show()
                time.sleep(delay)
Example #3
0
    def render_meter(percent, y_range=range(7), meter_minnum=0):
        # calculate percent
        x_range = int(DotMatrix.METER_WIDTH * (percent / 100.0))
        #print("x_range = " + str(x_range))

        # set_pixel
        render_counter = 0
        for i in range(WIDTH):
            # skip invisible matrix
            if i in DotMatrix.SKIP_LIST:
                continue

            # increment render counter
            render_counter = render_counter + 1

            # meter count check
            if i >= meter_minnum and render_counter > x_range:
                break

            # render up to down
            for k in y_range:
                set_pixel(i, k, 1)
Example #4
0
def write_customchar(char, offset_x=0, offset_y=0):
    for x in range(5):
        for y in range(7):
            p = (char[x] & (1 << y)) > 0
            set_pixel(offset_x + x, offset_y + y, p)
Example #5
0
#!/usr/bin/env python

import math
import time

from microdotphat import clear, set_pixel, show


print("""Sine Wave

Displays a sine wave across your pHAT.

Press Ctrl+C to exit.
""")

while True:
    clear()
    t = time.time() * 10
    for x in range(45):
        y = int((math.sin(t + (x/2.5)) + 1) * 3.5)
        set_pixel(x, y, 1)
        
    show()
    time.sleep(0.01)
lines = ["In the old #BILGETANK we'll keep you in the know",
         "In the old #BILGETANK we'll fix your techie woes",
         "And we'll make things",
         "And we'll break things",
         "'til we're altogether aching",
         "Then we'll grab a cup of grog down in the old #BILGETANK"]

lengths = [0] * len(lines)

offset_left = 0

for line, text in enumerate(lines):
    lengths[line] = write_string(text, offset_x=offset_left, offset_y=line_height * line)
    offset_left += lengths[line]

set_pixel(0, (len(lines) * line_height) - 1, 0)

current_line = 0

show()

while True:
    pos_x = 0
    pos_y = 0
    for current_line in range(len(lines)):
        time.sleep(delay*10)
        for y in range(lengths[current_line]):
            scroll(1,0)
            pos_x += 1
            time.sleep(delay)
            show()
import sys
import json
import time
from microdotphat import clear, show, scroll, write_string, set_pixel

while True:
    line = sys.stdin.readline()
    if line:
        #print('line', line)
        cmd = json.loads(line)
        if cmd['cmd'] == 'clear':
            clear()
        if cmd['cmd'] == 'write_string':
            write_string(cmd['arg1'], kerning=False)
            show()
        if cmd['cmd'] == 'write_string_scroll':  # breaks everything
            write_string(cmd['arg1'])
            scroll()
            show()
        if cmd['cmd'] == 'set_pixel':
            set_pixel(cmd['arg1'], cmd['arg2'], cmd['arg3'])
            show()

    time.sleep(0.1)
Example #8
0
    "And we'll make things", "And we'll break things",
    "'til we're altogether aching",
    "Then we'll grab a cup of grog down in the old #BILGETANK"
]

lengths = [0] * len(lines)

offset_left = 0

for line, text in enumerate(lines):
    lengths[line] = write_string(text,
                                 offset_x=offset_left,
                                 offset_y=line_height * line)
    offset_left += lengths[line]

set_pixel(0, (len(lines) * line_height) - 1, 0)

current_line = 0

show()

while True:
    pos_x = 0
    pos_y = 0
    for current_line in range(len(lines)):
        time.sleep(delay * 10)
        for y in range(lengths[current_line]):
            scroll(1, 0)
            pos_x += 1
            time.sleep(delay)
            show()
Example #9
0
 rand_x4 = randint(0,45)
 rand_y4 = randint(0,6)
 rand_x5 = randint(0,45)
 rand_y5 = randint(0,6)
 rand_x6 = randint(0,45)
 rand_y6 = randint(0,6)
 rand_x7 = randint(0,45)
 rand_y7 = randint(0,6)
 rand_x8 = randint(0,45)
 rand_y8 = randint(0,6)
 """
 clear()
 show()
 time.sleep(t)
 for x in range(6):
     set_pixel(x,0,1)
     set_pixel(x,2,1)
     set_pixel(x,4,1)
     set_pixel(x,6,1)
     show()
    
 for x in range(6,13):
     set_pixel(x,0,1)
     set_pixel(x,2,1)
     set_pixel(x,4,1)
     set_pixel(x,6,1)
     show()
 
 for x in range(13,21):
     set_pixel(x,0,1)
     set_pixel(x,2,1)
Example #10
0
def write_customchar(char, offset_x=0, offset_y=0):
    for x in range(5):
        for y in range(7):
            p = (char[x] & (1 << y)) > 0
            set_pixel(offset_x + x, offset_y + y, p)
def char_euro():
    set_pixel(2, 0, 1)
    set_pixel(3, 0, 1)
    set_pixel(4, 0, 1)

    set_pixel(1, 1, 1)

    set_pixel(0, 2, 1)
    set_pixel(1, 2, 1)
    set_pixel(2, 2, 1)
    set_pixel(3, 2, 1)

    set_pixel(0, 3, 1)

    set_pixel(0, 4, 1)
    set_pixel(1, 4, 1)
    set_pixel(2, 4, 1)
    set_pixel(3, 4, 1)

    set_pixel(1, 5, 1)

    set_pixel(2, 6, 1)
    set_pixel(3, 6, 1)
    set_pixel(4, 6, 1)