From dd8bcc2da80d15280b9aa94cec648fbdac576cc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20Ko=C4=8D=C3=AD?= Date: Tue, 18 Jul 2017 20:11:12 +0200 Subject: Add matrix --- turtetris_master/__init__.py | 8 ++++++++ turtetris_master/led_output.py | 31 +++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) (limited to 'turtetris_master') diff --git a/turtetris_master/__init__.py b/turtetris_master/__init__.py index 9cf22b1..401accb 100644 --- a/turtetris_master/__init__.py +++ b/turtetris_master/__init__.py @@ -1,11 +1,19 @@ +import time +from .led_output import Matrix from .usb_input import Gamepad def main(): "Main function" inpt = Gamepad() + print('Gamepad initialized') + mtrx = Matrix() + print('Matrix initialized') while True: + print('loop!!!!') print(inpt.check()) + mtrx.display() + time.sleep(1) if __name__ == '__main__': diff --git a/turtetris_master/led_output.py b/turtetris_master/led_output.py index e69de29..7af7a35 100644 --- a/turtetris_master/led_output.py +++ b/turtetris_master/led_output.py @@ -0,0 +1,31 @@ +import zmq +import json + + +class Matrix: + "Leds matrix" + + def __init__(self): + "Establish connection to matrix" + self.__mat__ = [[{ + 'color': '000000', + 'intens': 0 + }]*12]*10 + self.context = zmq.Context() + self.socket = self.context.socket(zmq.PUB) + self.socket.bind('tcp://*:4444') + + def display(self): + "Display matrix to leds" + for i in range(0, 10): + self.socket.send_string('line' + str(i) + ' ' + + json.dumps(self.__mat__[i])) + + def pixel(self, x, y, color=None, bright=None): + "Set pixel in matrix" + if x < 0 or x > 11 or y < 0 or y > 9: + return # just ignore any pixel outside of the matrix + if color is not None: + self.__mat__[y][x]['color'] = color + if bright is not None: + self.__mat__[y][x]['bright'] = bright -- cgit v1.2.3