diff options
author | Karel Kočí <karel.koci@nic.cz> | 2017-07-18 20:11:12 +0200 |
---|---|---|
committer | Karel Kočí <karel.koci@nic.cz> | 2017-07-19 10:15:02 +0200 |
commit | dd8bcc2da80d15280b9aa94cec648fbdac576cc3 (patch) | |
tree | bac1f0e7b71b18414753e4ddfb507d70b79a0923 /turtetris_master | |
parent | 0a9a2fd752b03e1796ed6ce110ee939f0eb773e6 (diff) | |
download | turris-tetris-dd8bcc2da80d15280b9aa94cec648fbdac576cc3.tar.gz turris-tetris-dd8bcc2da80d15280b9aa94cec648fbdac576cc3.tar.bz2 turris-tetris-dd8bcc2da80d15280b9aa94cec648fbdac576cc3.zip |
Add matrix
Diffstat (limited to 'turtetris_master')
-rw-r--r-- | turtetris_master/__init__.py | 8 | ||||
-rw-r--r-- | turtetris_master/led_output.py | 31 |
2 files changed, 39 insertions, 0 deletions
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 |