def try_bricklet(self, uid, device_identifier, position): if device_identifier == 231 and "taskint" not in self.outputs: self.device = BrickletLEDStrip(uid, self.controller.ipcon) self.outputs["taskint"] = { "name": "Task Intensity", "type": "dimmer", } self.outputs["taskcol"] = { "name": "Task Colour", "type": "select", } self.device.set_chip_type(self.device.CHIP_TYPE_WS2811) self.device.set_channel_mapping(self.device.CHANNEL_MAPPING_BRG) print("Created LEDBrick Output")
def __init__(self): # Attribute importiert self.__UIDmaster = matrixProperties.UIDmaster # "6et15y" self.__UIDbricklet = matrixProperties.UIDbricklet # "wVj" self.__HOST = matrixProperties.HOST # "localhost" self.__PORT = matrixProperties.PORT # 4223 self.__matrixIndexRed = matrixProperties.IndexRed # 0 self.__matrixIndexGreen = matrixProperties.IndexGreen # 1 self.__matrixIndexBlue = matrixProperties.IndexBlue # 2 self.__rows = matrixProperties.ROWS # 10 self.__columns = matrixProperties.COLUMNS # 20 self.__LEDnr = matrixProperties.LEDnr # Liste LED-Nummern 0 bis 199 self.__numLEDS = matrixProperties.NUM_LEDS # 16 self.__rgb = [[0 for i in range(self.__numLEDS)] for i in range(3)] # RGB-Array self.__image = matrixProperties.defaultImage # Default-Bild setzen self.__imageIndexRed = 0 self.__imageIndexGreen = 1 self.__imageIndexBlue = 2 # Instanzvariablen self.__light = True # Boolean: True / False # Objekte print("Instanz LEDmatrix wurde erstellt.") self.__ipcon = IPConnection() # Create IP connection self.__masterBrick = BrickMaster(self.__UIDmaster, self.__ipcon) self.__brickletLEDstrip = BrickletLEDStrip( self.__UIDbricklet, self.__ipcon) # Create device object # Connect to brickd --> Verbindung Masterbrick? richtiger RGB-Kanal einstellen? self.__ipcon.connect(self.__HOST, self.__PORT) print("Verbindung zu brickd hergestellt.") self.__brickletLEDstrip.set_frame_duration( 20) # Anzeigedauer Bild: 20ms ergibt 20 Bilder pro Sekunde self.__brickletLEDstrip.set_channel_mapping( self.__brickletLEDstrip.CHANNEL_MAPPING_RGB ) # CHANNEL_MAPPING_RGB = 6 -> Farbkanal definieren (RGB statt BGR) # Callback starten self.__brickletLEDstrip.register_callback( self.__brickletLEDstrip.CALLBACK_FRAME_RENDERED, lambda x: self.__loadPicture__()) print("Callback aktiviert.")
def cb_enumerate(uid, connected_uid, position, hardware_version, firmware_version, device_identifier, enumeration_type): print("UID: " + uid) print("Enumeration Type: " + str(enumeration_type)) if enumeration_type == IPConnection.ENUMERATION_TYPE_DISCONNECTED: print("") return print("Connected UID: " + connected_uid) print("Position: " + position) print("Hardware Version: " + str(hardware_version)) print("Firmware Version: " + str(firmware_version)) print("Device Identifier: " + str(device_identifier)) print("") if device_identifier == LED_BRICKLET: print(device_identifier, uid, ipcon) led_bricklet = BrickletLEDStrip(uid, ipcon) draw(led_bricklet, TEXT)
def __init__(self): # Attribute importiert self.__UIDmaster = matrixProperties.UIDmaster # "6et15y" self.__UIDbricklet = matrixProperties.UIDbricklet # "wVj" self.__HOST = matrixProperties.HOST # "localhost" self.__PORT = matrixProperties.PORT # 4223 self.__matrixIndexRed = matrixProperties.IndexRed # 0 self.__matrixIndexGreen = matrixProperties.IndexGreen # 1 self.__matrixIndexBlue = matrixProperties.IndexBlue # 2 self.__rows = matrixProperties.ROWS # 10 self.__columns = matrixProperties.COLUMNS # 20 self.__LEDnr = matrixProperties.LEDnr # Liste LED-Nummern 0 bis 199 self.__numLEDS = matrixProperties.NUM_LEDS # 16 self.__rgb = [[0 for i in range(self.__numLEDS)] for i in range(3)] # RGB-Array self.__image = matrixProperties.defaultImage # Default-Bild setzen self.__imageIndexRed = 0 self.__imageIndexGreen = 1 self.__imageIndexBlue = 2 # Instanzvariablen self.__light = True # Boolean: True / False # Objekte print("Instanz LEDmatrix wurde erstellt.") self.__ipcon = IPConnection() # Create IP connection self.__masterBrick = BrickMaster(self.__UIDmaster, self.__ipcon) self.__brickletLEDstrip = BrickletLEDStrip(self.__UIDbricklet, self.__ipcon) # Create device object # Connect to brickd --> Verbindung Masterbrick? richtiger RGB-Kanal einstellen? self.__ipcon.connect(self.__HOST, self.__PORT) print("Verbindung zu brickd hergestellt.") self.__brickletLEDstrip.set_frame_duration(20) # Anzeigedauer Bild: 20ms ergibt 20 Bilder pro Sekunde self.__brickletLEDstrip.set_channel_mapping(self.__brickletLEDstrip.CHANNEL_MAPPING_RGB) # CHANNEL_MAPPING_RGB = 6 -> Farbkanal definieren (RGB statt BGR) # Callback starten self.__brickletLEDstrip.register_callback(self.__brickletLEDstrip.CALLBACK_FRAME_RENDERED, lambda x: self.__loadPicture__()) print("Callback aktiviert.")
for y in range(anzahl): if g_index % 2 == 0: r_index = Ys[y] - 1 else: r_index = 10 - Ys[y] red[g_index - 1][r_index] = r green[g_index - 1][r_index] = g blue[g_index - 1][r_index] = b if __name__ == "__main__": ipcon = IPConnection() ls = BrickletLEDStrip(UID, ipcon) ipcon.connect(HOST, PORT) fClear() sleep(1) setColor(255, 255, 255) yLine(1) yLine(10) fOn() while True: while puls != 0:
b[r_index] = 255 - (g_index + r_index) * 255 / 200 if g_index == 200: r_index = NUM_LEDS - 1 if g_index > 0: ls.set_rgb_values(g_index - NUM_LEDS, NUM_LEDS, [0] * 16, [0] * 16, [0] * 16) # Set new data for next render cycle ls.set_rgb_values(g_index, NUM_LEDS, r, g, b) if __name__ == "__main__": ipcon = IPConnection() # Create IP connection ls = BrickletLEDStrip(UID, ipcon) # Create device object ipcon.connect(HOST, PORT) # Connect to brickd # Don't use device before ipcon is connected # Set frame duration to 50ms (20 frames per second) ls.set_frame_duration(10) # Register frame rendered callback to function cb_frame_rendered ls.register_callback(ls.CALLBACK_FRAME_RENDERED, lambda x: cb_frame_rendered(x, ls, 0, 0, 255)) # Set initial rgb values to get started ls.set_rgb_values(0, NUM_LEDS, r, g, b)
for y in range(anzahl): if g_index % 2 == 1: r_index = Ys[y] - 1 else: r_index = 10 - Ys[y] red[g_index - 1][r_index] = r green[g_index - 1][r_index] = g blue[g_index - 1][r_index] = b if __name__ == "__main__": ipcon = IPConnection() ls = BrickletLEDStrip(UID, ipcon) ipcon.connect(HOST, PORT) fClear() sleep(1) ls.set_frame_duration(1) ls.register_callback( ls.CALLBACK_FRAME_RENDERED, lambda w: fLight( x, anzahl, y1, y2, y3, y4, y5, y6, y7, y8, y9, y10, r, g, b)) setColor(255, 255, 255) xLine(7)
#!/usr/bin/env python # -*- coding: utf-8 -*- HOST = "localhost" PORT = 4223 UID = "XYZ" # Change XYZ to the UID of your LED Strip Bricklet from tinkerforge.ip_connection import IPConnection from tinkerforge.bricklet_led_strip import BrickletLEDStrip if __name__ == "__main__": ipcon = IPConnection() # Create IP connection ls = BrickletLEDStrip(UID, ipcon) # Create device object ipcon.connect(HOST, PORT) # Connect to brickd # Don't use device before ipcon is connected # Set first 10 LEDs to green ls.set_rgb_values(0, 10, [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) input("Press key to exit\n") # Use raw_input() in Python 2 ipcon.disconnect()
class LEDmatrixConnect(object): """ init() wird automatisch nach der Erzeugung der Instanz aufgerufen. (-> magische Methode) Erstellt ein device Objekt und baut die Verbindung zu brickd auf. (Verbindung zu Master Brick????) """ # @LEDmatrix.route('ledmatrix.bfh.ch/api/v1.0/LEDmatrixConnect[POST]) def __init__(self): # Attribute importiert self.__UIDmaster = matrixProperties.UIDmaster # "6et15y" self.__UIDbricklet = matrixProperties.UIDbricklet # "wVj" self.__HOST = matrixProperties.HOST # "localhost" self.__PORT = matrixProperties.PORT # 4223 self.__matrixIndexRed = matrixProperties.IndexRed # 0 self.__matrixIndexGreen = matrixProperties.IndexGreen # 1 self.__matrixIndexBlue = matrixProperties.IndexBlue # 2 self.__rows = matrixProperties.ROWS # 10 self.__columns = matrixProperties.COLUMNS # 20 self.__LEDnr = matrixProperties.LEDnr # Liste LED-Nummern 0 bis 199 self.__numLEDS = matrixProperties.NUM_LEDS # 16 self.__rgb = [[0 for i in range(self.__numLEDS)] for i in range(3)] # RGB-Array self.__image = matrixProperties.defaultImage # Default-Bild setzen self.__imageIndexRed = 0 self.__imageIndexGreen = 1 self.__imageIndexBlue = 2 # Instanzvariablen self.__light = True # Boolean: True / False # Objekte print("Instanz LEDmatrix wurde erstellt.") self.__ipcon = IPConnection() # Create IP connection self.__masterBrick = BrickMaster(self.__UIDmaster, self.__ipcon) self.__brickletLEDstrip = BrickletLEDStrip( self.__UIDbricklet, self.__ipcon) # Create device object # Connect to brickd --> Verbindung Masterbrick? richtiger RGB-Kanal einstellen? self.__ipcon.connect(self.__HOST, self.__PORT) print("Verbindung zu brickd hergestellt.") self.__brickletLEDstrip.set_frame_duration( 20) # Anzeigedauer Bild: 20ms ergibt 20 Bilder pro Sekunde self.__brickletLEDstrip.set_channel_mapping( self.__brickletLEDstrip.CHANNEL_MAPPING_RGB ) # CHANNEL_MAPPING_RGB = 6 -> Farbkanal definieren (RGB statt BGR) # Callback starten self.__brickletLEDstrip.register_callback( self.__brickletLEDstrip.CALLBACK_FRAME_RENDERED, lambda x: self.__loadPicture__()) print("Callback aktiviert.") # ======= private Methoden ========================================================================== # fillRGBs(), fillAsc(), fillDesc(), loadPicture() def __fillRGBs__(self, yMatrix, xImage, yImage): """ Private Methode: Füllt die Farbinformationen für einen Pixel in die einzelnen RGB-Arrays ab. """ self.__rgb[self.__matrixIndexRed][yMatrix] = self.__image[xImage][ yImage][self.__imageIndexRed] self.__rgb[self.__matrixIndexGreen][yMatrix] = self.__image[xImage][ yImage][self.__imageIndexGreen] self.__rgb[self.__matrixIndexBlue][yMatrix] = self.__image[xImage][ yImage][self.__imageIndexBlue] def __fillAsc__(self, xImage, yMatrix): """ Private Methode: Füllt eine Spalte für die LED-Matrix aus (von unten nach oben) """ # 0 bis 9 yImage = 0 i = 0 while (i < self.__rows): # i < 10 self.__fillRGBs__(yMatrix, xImage, yImage) i += 1 yImage += 1 yMatrix += 1 if (yMatrix >= self.__rows): yMatrix = 0 def __fillDesc__(self, xImage, yMatrix): """ Private Methode: Füllt eine Spalte für die LED-Matrix aus (von oben nach unten) """ # 9 bis 0 yImage = 0 i = 0 while (i < self.__rows): # i < 10 self.__fillRGBs__(yMatrix, xImage, yImage) i += 1 yImage += 1 yMatrix -= 1 if (yMatrix < 0): yMatrix = self.__rows - 1 def __loadPicture__(self): """ Methode lädt ein ganzes Bild, sofern self.__light auf True gesetzt ist => Licht an. """ if (self.__light is True): xMatrix = 0 yMatrix = 0 xImage = 0 columns = self.__columns # 20 while (columns > 0): if ( xMatrix % 2 == 0 ): # Farbwerte von image-array nach rgb-array bei gerader Spalte y = 0 self.__fillAsc__(xImage, yMatrix) else: # Farbwerte von image-array nach rgb-array bei ungerader Spalte y = self.__rows - 1 self.__fillDesc__(xImage, self.__rows - (yMatrix + 1)) # Aufrufen der Methode set_rgb_values(index, length, r, g, b). (r, g, b, verlangen 16er-Array's) self.__brickletLEDstrip.set_rgb_values( self.__LEDnr[xMatrix][y], self.__rows, # self.__rows = 10 self.__rgb[self.__matrixIndexRed], self.__rgb[self.__matrixIndexGreen], self.__rgb[self.__matrixIndexBlue]) columns -= 1 xImage += 1 xMatrix += 1 if xMatrix >= self.__columns: xMatrix = 0 xImage = 0 # ======= public Methoden ================================================== # connect(), finish(), setVelocity(), lightOff(), setImage(), getImage() # @LEDmatrix.route('ledmatrix.bfh.ch/api/v1.0/LEDmatrixConnect/connect[PUT]) def connect(self): """ Verbindungsaufbau """ self.__ipcon.connect(self.__HOST, self.__PORT) print("Verbindung zu brickd hergestellt.") # @LEDmatrix.route('ledmatrix.bfh.ch/api/v1.0/LEDmatrixConnect/finish[PUT]) def finish(self): """ Beendet die Verbindung. """ # input("Press key to exit\n") self.__ipcon.disconnect() print("Verbindung beendet.") # @LEDmatrix.route('ledmatrix.bfh.ch/api/v1.0/LEDmatrixConnect/setVelocity/<int:frequenz>[PUT]) def setFrameDuration(self, millisec: int = 20): """ Set frame duration to 50ms (20 frames per second). Verändert die Anzeigedauer eines Frames. :param millisec: int """ self.__brickletLEDstrip.set_frame_duration(millisec) # @LEDmatrix.route('ledmatrix.bfh.ch/api/v1.0/LEDmatrixConnect/getFrameDuration[GET]) def getFrameDuration(self) -> int: """ Gibt einen int-Wert zurück. Anzeigedauer der Frames auf dem LED-Display. (20ms entspricht 50 Bilder/Sekunde) :return frame duration: int """ return self.__brickletLEDstrip.get_frame_duration() # @LEDmatrix.route('ledmatrix.bfh.ch/api/v1.0/LEDmatrixConnect/light/<boolean:status>[PUT]) def light(self, status: bool = True): # status = boolean True / False """ Licht-Regelung auf 'unterster' Stufe, wirkt sich auf den gesamten LED-Display. True = 'Licht an', False = 'Licht aus' :param status: boolean """ self.__light = status time.sleep(1) if (status is False): i = 0 while i < self.__columns: # hier 20 self.__brickletLEDstrip.set_rgb_values(i * 10, 10, [0] * self.__numLEDS, [0] * self.__numLEDS, [0] * self.__numLEDS) i += 1 # @LEDmatrix.route('ledmatrix.bfh.ch/api/v1.0/LEDmatrixConnect/setImage/<list:image>[PUT]) def setImage(self, image: list): """ Liste mit den RGB-Werten der Form [[[red, green, blue] for i in range(x columns)] for i in range(y rows)] :param image: list """ self.__image = image # @LEDmatrix.route('ledmatrix.bfh.ch/api/v1.0/LEDmatrixConnect/setImageRGBindex/<int:red>/<int:green>/<int:blue>[PUT]) def setImageRGBindex(self, red: int, green: int, blue: int): """ Werte: 0 bis 2, Default: red = 0, green = 1, blue = 2 :param red: int :param green: int :param blue: int """ self.__imageIndexRed = red self.__imageIndexGreen = green self.__imageIndexBlue = blue
#!/usr/bin/env python # -*- coding: utf-8 -*- HOST = "localhost" PORT = 4223 UID = "XYZ" # Change XYZ to the UID of your LED Strip Bricklet from tinkerforge.ip_connection import IPConnection from tinkerforge.bricklet_led_strip import BrickletLEDStrip if __name__ == "__main__": ipcon = IPConnection() # Create IP connection ls = BrickletLEDStrip(UID, ipcon) # Create device object ipcon.connect(HOST, PORT) # Connect to brickd # Don't use device before ipcon is connected # Set first 10 LEDs to green ls.set_rgb_values(0, 10, [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) raw_input("Press key to exit\n") # Use input() in Python 3 ipcon.disconnect()
def cb_frame_rendered(length, ls): global r_index b[r_index] = 0 if r_index == NUM_LEDS-1: r_index = 0 else: r_index += 1 b[r_index] = 255 # Set new data for next render cycle ls.set_rgb_values(0, NUM_LEDS, r, g, b) if __name__ == "__main__": ipcon = IPConnection() # Create IP connection ls = BrickletLEDStrip(UID, ipcon) # Create device object ipcon.connect(HOST, PORT) # Connect to brickd # Don't use device before ipcon is connected # Set frame duration to 50ms (20 frames per second) ls.set_frame_duration(50) # Register frame rendered callback to function cb_frame_rendered ls.register_callback(ls.CALLBACK_FRAME_RENDERED, lambda x: cb_frame_rendered(x, ls)) # Set initial rgb values to get started ls.set_rgb_values(0, NUM_LEDS, r, g, b) raw_input("Press key to exit\n") # Use input() in Python 3
class LEDmatrixConnect(object): """ init() wird automatisch nach der Erzeugung der Instanz aufgerufen. (-> magische Methode) Erstellt ein device Objekt und baut die Verbindung zu brickd auf. (Verbindung zu Master Brick????) """ # @LEDmatrix.route('ledmatrix.bfh.ch/api/v1.0/LEDmatrixConnect[POST]) def __init__(self): # Attribute importiert self.__UIDmaster = matrixProperties.UIDmaster # "6et15y" self.__UIDbricklet = matrixProperties.UIDbricklet # "wVj" self.__HOST = matrixProperties.HOST # "localhost" self.__PORT = matrixProperties.PORT # 4223 self.__matrixIndexRed = matrixProperties.IndexRed # 0 self.__matrixIndexGreen = matrixProperties.IndexGreen # 1 self.__matrixIndexBlue = matrixProperties.IndexBlue # 2 self.__rows = matrixProperties.ROWS # 10 self.__columns = matrixProperties.COLUMNS # 20 self.__LEDnr = matrixProperties.LEDnr # Liste LED-Nummern 0 bis 199 self.__numLEDS = matrixProperties.NUM_LEDS # 16 self.__rgb = [[0 for i in range(self.__numLEDS)] for i in range(3)] # RGB-Array self.__image = matrixProperties.defaultImage # Default-Bild setzen self.__imageIndexRed = 0 self.__imageIndexGreen = 1 self.__imageIndexBlue = 2 # Instanzvariablen self.__light = True # Boolean: True / False # Objekte print("Instanz LEDmatrix wurde erstellt.") self.__ipcon = IPConnection() # Create IP connection self.__masterBrick = BrickMaster(self.__UIDmaster, self.__ipcon) self.__brickletLEDstrip = BrickletLEDStrip(self.__UIDbricklet, self.__ipcon) # Create device object # Connect to brickd --> Verbindung Masterbrick? richtiger RGB-Kanal einstellen? self.__ipcon.connect(self.__HOST, self.__PORT) print("Verbindung zu brickd hergestellt.") self.__brickletLEDstrip.set_frame_duration(20) # Anzeigedauer Bild: 20ms ergibt 20 Bilder pro Sekunde self.__brickletLEDstrip.set_channel_mapping(self.__brickletLEDstrip.CHANNEL_MAPPING_RGB) # CHANNEL_MAPPING_RGB = 6 -> Farbkanal definieren (RGB statt BGR) # Callback starten self.__brickletLEDstrip.register_callback(self.__brickletLEDstrip.CALLBACK_FRAME_RENDERED, lambda x: self.__loadPicture__()) print("Callback aktiviert.") # ======= private Methoden ========================================================================== # fillRGBs(), fillAsc(), fillDesc(), loadPicture() def __fillRGBs__(self, yMatrix, xImage, yImage): """ Private Methode: Füllt die Farbinformationen für einen Pixel in die einzelnen RGB-Arrays ab. """ self.__rgb[self.__matrixIndexRed][yMatrix] = self.__image[xImage][yImage][self.__imageIndexRed] self.__rgb[self.__matrixIndexGreen][yMatrix] = self.__image[xImage][yImage][self.__imageIndexGreen] self.__rgb[self.__matrixIndexBlue][yMatrix] = self.__image[xImage][yImage][self.__imageIndexBlue] def __fillAsc__(self, xImage, yMatrix): """ Private Methode: Füllt eine Spalte für die LED-Matrix aus (von unten nach oben) """ # 0 bis 9 yImage = 0 i = 0 while (i < self.__rows): # i < 10 self.__fillRGBs__(yMatrix, xImage, yImage) i += 1 yImage += 1 yMatrix += 1 if (yMatrix >= self.__rows): yMatrix = 0 def __fillDesc__(self, xImage, yMatrix): """ Private Methode: Füllt eine Spalte für die LED-Matrix aus (von oben nach unten) """ # 9 bis 0 yImage = 0 i = 0 while (i < self.__rows): # i < 10 self.__fillRGBs__(yMatrix, xImage, yImage) i += 1 yImage += 1 yMatrix -= 1 if (yMatrix < 0): yMatrix = self.__rows - 1 def __loadPicture__(self): """ Methode lädt ein ganzes Bild, sofern self.__light auf True gesetzt ist => Licht an. """ if (self.__light is True): xMatrix = 0 yMatrix = 0 xImage = 0 columns = self.__columns # 20 while (columns > 0): if (xMatrix % 2 == 0): # Farbwerte von image-array nach rgb-array bei gerader Spalte y = 0 self.__fillAsc__(xImage, yMatrix) else: # Farbwerte von image-array nach rgb-array bei ungerader Spalte y = self.__rows - 1 self.__fillDesc__(xImage, self.__rows - (yMatrix + 1)) # Aufrufen der Methode set_rgb_values(index, length, r, g, b). (r, g, b, verlangen 16er-Array's) self.__brickletLEDstrip.set_rgb_values(self.__LEDnr[xMatrix][y], self.__rows, # self.__rows = 10 self.__rgb[self.__matrixIndexRed], self.__rgb[self.__matrixIndexGreen], self.__rgb[self.__matrixIndexBlue]) columns -= 1 xImage += 1 xMatrix += 1 if xMatrix >= self.__columns: xMatrix = 0 xImage = 0 # ======= public Methoden ================================================== # connect(), finish(), setVelocity(), lightOff(), setImage(), getImage() # @LEDmatrix.route('ledmatrix.bfh.ch/api/v1.0/LEDmatrixConnect/connect[PUT]) def connect(self): """ Verbindungsaufbau """ self.__ipcon.connect(self.__HOST, self.__PORT) print("Verbindung zu brickd hergestellt.") # @LEDmatrix.route('ledmatrix.bfh.ch/api/v1.0/LEDmatrixConnect/finish[PUT]) def finish(self): """ Beendet die Verbindung. """ # input("Press key to exit\n") self.__ipcon.disconnect() print("Verbindung beendet.") # @LEDmatrix.route('ledmatrix.bfh.ch/api/v1.0/LEDmatrixConnect/setVelocity/<int:frequenz>[PUT]) def setFrameDuration(self, millisec: int = 20): """ Set frame duration to 50ms (20 frames per second). Verändert die Anzeigedauer eines Frames. :param millisec: int """ self.__brickletLEDstrip.set_frame_duration(millisec) # @LEDmatrix.route('ledmatrix.bfh.ch/api/v1.0/LEDmatrixConnect/getFrameDuration[GET]) def getFrameDuration(self) -> int: """ Gibt einen int-Wert zurück. Anzeigedauer der Frames auf dem LED-Display. (20ms entspricht 50 Bilder/Sekunde) :return frame duration: int """ return self.__brickletLEDstrip.get_frame_duration() # @LEDmatrix.route('ledmatrix.bfh.ch/api/v1.0/LEDmatrixConnect/light/<boolean:status>[PUT]) def light(self, status: bool = True): # status = boolean True / False """ Licht-Regelung auf 'unterster' Stufe, wirkt sich auf den gesamten LED-Display. True = 'Licht an', False = 'Licht aus' :param status: boolean """ self.__light = status time.sleep(1) if (status is False): i = 0 while i < self.__columns: # hier 20 self.__brickletLEDstrip.set_rgb_values(i * 10, 10, [0] * self.__numLEDS, [0] * self.__numLEDS, [0] * self.__numLEDS) i += 1 # @LEDmatrix.route('ledmatrix.bfh.ch/api/v1.0/LEDmatrixConnect/setImage/<list:image>[PUT]) def setImage(self, image: list): """ Liste mit den RGB-Werten der Form [[[red, green, blue] for i in range(x columns)] for i in range(y rows)] :param image: list """ self.__image = image # @LEDmatrix.route('ledmatrix.bfh.ch/api/v1.0/LEDmatrixConnect/setImageRGBindex/<int:red>/<int:green>/<int:blue>[PUT]) def setImageRGBindex(self, red: int, green: int, blue: int): """ Werte: 0 bis 2, Default: red = 0, green = 1, blue = 2 :param red: int :param green: int :param blue: int """ self.__imageIndexRed = red self.__imageIndexGreen = green self.__imageIndexBlue = blue
class LightingModule(StateModule): menu_title = "Lighting" outputs = {} edit = False device = None current = 0 intens = 100 color = 0 colors = [ { "name": "Warm", "color": (255, 160, 25) }, { "name": "Cool", "color": (255, 255, 50) }, { "name": "Red", "color": (255, 0, 0) }, { "name": "Blue", "color": (0, 0, 255) }, { "name": "Magenta", "color": (255, 0, 255) }, { "name": "Green", "color": (0, 255, 0) }, ] def __init__(self, controller): super(LightingModule, self).__init__(controller) self.set_light() def draw(self, clear=True): if clear: self.controller.screen.device.clear_display() if not len(self.outputs): self.controller.screen.draw("values", {}) return outputs = self.outputs[self.outputs.keys()[self.current]] if self.edit: name = outputs["name"] + "*" else: name = outputs["name"] if outputs["type"] == "dimmer": self.controller.screen.draw("values", { "title": name, "value": str(self.intens) + " %", }) if outputs["type"] == "select": self.controller.screen.draw( "values", { "title": name, "value": str(self.colors[self.color]["name"]), }) def try_bricklet(self, uid, device_identifier, position): if device_identifier == 231 and "taskint" not in self.outputs: self.device = BrickletLEDStrip(uid, self.controller.ipcon) self.outputs["taskint"] = { "name": "Task Intensity", "type": "dimmer", } self.outputs["taskcol"] = { "name": "Task Colour", "type": "select", } self.device.set_chip_type(self.device.CHIP_TYPE_WS2811) self.device.set_channel_mapping(self.device.CHANNEL_MAPPING_BRG) print("Created LEDBrick Output") def change_light(self, direction): if self.outputs[self.outputs.keys()[self.current]]["type"] == "dimmer": if direction == "up" and self.intens < 100: self.intens += 10 elif direction == "down" and self.intens > 0: self.intens -= 10 else: if direction == "up": if self.color >= len(self.colors) - 1: self.color = 0 else: self.color += 1 elif direction == "down": if self.color <= 0: self.color = len(self.colors) - 1 else: self.color -= 1 # print "change " + direction + str(self.color) def set_light(self): if self.device: color = self.colors[self.color]["color"] color = (int(color[0] * self.intens / 100), int(color[1] * self.intens / 100), int(color[2] * self.intens / 100)) r = [color[0] for i in range(16)] b = [color[1] for i in range(16)] g = [color[2] for i in range(16)] self.device.set_rgb_values(0, 16, r, b, g) r = [255 for i in range(16)] b = [0 for i in range(16)] g = [0 for i in range(16)] self.device.set_rgb_values(17, 1, r, b, g) self.controller.scheduler.enter( 1, 1, self.set_light, (), ) def navigate(self, direction): if not self.edit: if direction == "forward": self.edit = True self.draw() if direction == "back": self.controller.prev_module() if direction in ["down", "up"]: if direction == "down": self.current = self.current + 1 else: self.current = self.current - 1 if self.current >= len(self.outputs): self.current = 0 elif self.current < 0: self.current = len(self.outputs) - 1 # print "Output: " + str(list(self.outputs)[self.current]) self.draw() else: if direction == "back": self.edit = False self.draw() if direction in ["down", "up"]: self.change_light(direction) self.draw() def tick(self): self.draw(clear=False)
#!/usr/bin/env python # -*- coding: utf-8 -*- HOST = "localhost" PORT = 4223 UID = "wVj" # Change XYZ to the UID of your LED Strip Bricklet from tinkerforge.ip_connection import IPConnection from tinkerforge.bricklet_led_strip import BrickletLEDStrip if __name__ == "__main__": ipcon = IPConnection() # Create IP connection ls = BrickletLEDStrip(UID, ipcon) # Create device object ipcon.connect(HOST, PORT) # Connect to brickd # Don't use device before ipcon is connected while 1==1: # Set first 10 LEDs to green ls.set_frame_duration(1) for i in range (13): r = [200, 0, 0, 200, 11*i, 11*i, 100, 11, 111, 111, 111, 11, 100, 123, 234, 255] g = [0, 190, 0, 255, 255, 255, 255, 11*i, 255, 255, 255, 200, 10, 20, 11, 11] b = [0, 0, 100, 150, 11, 77, 11*i, 11*i, 50, 55, 66, 255, 11, 234, 123, 11] ls.set_rgb_values(16*i, 16, r, g, b) raw_input("Press key to exit\n") # Use input() in Python 3 ipcon.disconnect()
#!/usr/bin/env python # -*- coding: utf-8 -*- HOST = "localhost" PORT = 4223 UID = "XYZ" # Change XYZ to the UID of your LED Strip Bricklet from tinkerforge.ip_connection import IPConnection from tinkerforge.bricklet_led_strip import BrickletLEDStrip if __name__ == "__main__": ipcon = IPConnection() # Create IP connection ls = BrickletLEDStrip(UID, ipcon) # Create device object ipcon.connect(HOST, PORT) # Connect to brickd # Don't use device before ipcon is connected # Set first 10 LEDs to green r = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] g = [255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0] b = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] ls.set_rgb_values(0, 10, r, g, b) raw_input("Press key to exit\n") # Use input() in Python 3 ipcon.disconnect()