Beispiel #1
0
    def __init__(self, cfgopts):
        super().__init__(cfgopts)
        self.gpio_enable = None
        global TLC_LOADED
        global tlc5947

        if 'gpio_latch' not in self.CfgOptions:
            print('GPIO Latch pin not specified')
            return


        if TLC_LOADED is not True:
            import adafruit_tlc5947

            if 'gpio_enable' in self.CfgOptions:
                _gpio_enable_pin = getattr(board, 'D{0}'.format(self.CfgOptions['gpio_enable']))
                self.gpio_enable = digitalio.DigitalInOut(_gpio_enable_pin)
                self.gpio_enable.direction = digitalio.Direction.OUTPUT

            latch_pin = getattr(board, 'D{0}'.format(self.CfgOptions['gpio_latch']))
            spi = busio.SPI(clock=board.SCK, MOSI=board.MOSI)
            latch = digitalio.DigitalInOut(latch_pin)
            tlc5947 = adafruit_tlc5947.TLC5947(spi, latch)

            for i in range(0, 23):
                tlc5947[i] = 0

            self.gpio_enable.value = 1

            TLC_LOADED = True
Beispiel #2
0
 def __init__(self):
     threading.Thread.__init__(self)
     self.channels = [0] * 12
     spi = busio.SPI(clock=board.SCK, MOSI=board.MOSI)
     latch = digitalio.DigitalInOut(board.D5)
     self.tlc5947 = adafruit_tlc5947.TLC5947(spi, latch, num_drivers=1)
     for channel_number in range(len(self.channels)):
         self.channels[channel_number] = self.tlc5947.create_pwm_out(
             channel_number)
     self.queue = queue.Queue()
     self.led_groups = {
         "fruit_0":
         LED_Group(self.group_channels.FRUIT_0, self.queue),
         "fruit_1":
         LED_Group(self.group_channels.FRUIT_1, self.queue),
         "fruit_2":
         LED_Group(self.group_channels.FRUIT_2, self.queue),
         "fruit_3":
         LED_Group(self.group_channels.FRUIT_3, self.queue),
         "fruit_4":
         LED_Group(self.group_channels.FRUIT_4, self.queue),
         "dinero":
         LED_Group(self.group_channels.FRUIT_5, self.queue),
         "all_radial":
         LED_Group(self.group_channels.ALL_RADIAL, self.queue),
         "all_clockwise":
         LED_Group(self.group_channels.ALL_CLOCKWISE, self.queue),
     }
Beispiel #3
0
    def __init__(self):
        self.tlc5947 = None
        self.numberOfLeds = env.driverCount * numberOfLeds

        if (env.latchPin):
            spi = busio.SPI(board.SCLK, board.MOSI, board.MISO)
            latch = digitalio.DigitalInOut(getattr(board, env.latchPin))
            self.tlc5947 = adafruit_tlc5947.TLC5947(
                spi, latch, num_drivers=env.driverCount)
    def __init__(self):
        threading.Thread.__init__(self)
        self.channels = [0] * 72
        spi = busio.SPI(clock=board.SCK, MOSI=board.MOSI)
        latch = digitalio.DigitalInOut(board.D22)
        self.tlc5947 = adafruit_tlc5947.TLC5947(spi, latch, num_drivers=3)

        for channel_number in range(len(self.channels)):
            #print("new pwm out", channel_number)
            self.channels[channel_number] = self.tlc5947.create_pwm_out(
                channel_number)

        self.queue = queue.Queue()
        self.trail_rollover_right = Lights_Pattern(
            self.pattern_channels.TRAIL_ROLLOVER_RIGHT, self.queue)
        self.trail_rollover_left = Lights_Pattern(
            self.pattern_channels.TRAIL_ROLLOVER_LEFT, self.queue)
        self.trail_sling_right = Lights_Pattern(
            self.pattern_channels.TRAIL_SLING_RIGHT, self.queue)
        self.trail_sling_left = Lights_Pattern(
            self.pattern_channels.TRAIL_SLING_LEFT, self.queue)
        self.trail_pop_left = Lights_Pattern(
            self.pattern_channels.TRAIL_POP_LEFT, self.queue)
        self.trail_pop_right = Lights_Pattern(
            self.pattern_channels.TRAIL_POP_RIGHT, self.queue)
        self.trail_pop_middle = Lights_Pattern(
            self.pattern_channels.TRAIL_POP_CENTER, self.queue)
        self.trail_spinner = Lights_Pattern(
            self.pattern_channels.TRAIL_SPINNER, self.queue)
        self.pie_rollover_right = Lights_Pattern(
            self.pattern_channels.PIE_ROLLOVER_RIGHT, self.queue)
        self.pie_rollover_left = Lights_Pattern(
            self.pattern_channels.PIE_ROLLOVER_LEFT, self.queue)
        self.pie_sling_right = Lights_Pattern(
            self.pattern_channels.PIE_SLING_RIGHT, self.queue)
        self.pie_sling_left = Lights_Pattern(
            self.pattern_channels.PIE_SLING_LEFT, self.queue)
        self.pie_pop_left = Lights_Pattern(self.pattern_channels.PIE_POP_LEFT,
                                           self.queue)
        self.pie_pop_right = Lights_Pattern(
            self.pattern_channels.PIE_POP_RIGHT, self.queue)
        self.pie_pop_middle = Lights_Pattern(
            self.pattern_channels.PIE_POP_CENTER, self.queue)
        self.pie_spinner = Lights_Pattern(self.pattern_channels.PIE_SPINNER,
                                          self.queue)
        self.sign_arrow_left = Lights_Pattern(
            self.pattern_channels.SIGN_ARROW_LEFT, self.queue)
        self.sign_arrow_right = Lights_Pattern(
            self.pattern_channels.SIGN_ARROW_RIGHT, self.queue)
        self.sign_bottom_right = Lights_Pattern(
            self.pattern_channels.SIGN_BOTTOM_RIGHT, self.queue)
        self.sign_top = Lights_Pattern(self.pattern_channels.SIGN_TOP,
                                       self.queue)
        self.all = Lights_Pattern(self.pattern_channels.ALL, self.queue)
        #self.all_radial = Lights_Pattern(self.pattern_channels.ALL_RADIAL, self.queue)
        #self.all_clockwise = Lights_Pattern(self.pattern_channels.ALL_CLOCKWISE, self.queue)
        self.start()
def reset_key():
    SCK = board.SCK
    MOSI = board.MOSI
    LATCH = digitalio.DigitalInOut(board.D5)

    # Initialize SPI bus.
    spi = busio.SPI(clock=SCK, MOSI=MOSI)

    # Initialize TLC5947
    tlc5947 = adafruit_tlc5947.TLC5947(spi,
                                       LATCH,
                                       auto_write=False,
                                       num_drivers=4)
    for x in range(88):
        tlc5947[x] = 0
    tlc5947.write()
    def __init__(self, latch, driverCount):

        self.driver_count = driverCount

        # Initialize SPI bus.
        spi = busio.SPI(clock=board.SCK, MOSI=board.MOSI)

        # Initialize TLC5947
        self.tlc5947 = adafruit_tlc5947.TLC5947(spi,
                                                latch,
                                                num_drivers=driverCount)

        self.ledOut = []
        for idx in range(0, 24 * self.driver_count):
            print(idx)
            self.ledOut.append(self.tlc5947.create_pwm_out(idx))
def individual(x, val, iterations):
    SCK = board.SCK
    MOSI = board.MOSI
    LATCH = digitalio.DigitalInOut(board.D5)

    # Initialize SPI bus.
    spi = busio.SPI(clock=SCK, MOSI=MOSI)

    # Initialize TLC5947
    tlc5947 = adafruit_tlc5947.TLC5947(spi,
                                       LATCH,
                                       auto_write=False,
                                       num_drivers=4)
    for g in range(0, iterations):
        tlc5947[x] = val
        tlc5947.write()
        time.sleep(0.5)
        tlc5947[x] = 0
        tlc5947.write()
        time.sleep(0.5)
def testing():
    SCK = board.SCK
    MOSI = board.MOSI
    LATCH = digitalio.DigitalInOut(board.D5)

    # Initialize SPI bus.
    spi = busio.SPI(clock=SCK, MOSI=MOSI)

    # Initialize TLC5947
    tlc5947 = adafruit_tlc5947.TLC5947(spi,
                                       LATCH,
                                       auto_write=False,
                                       num_drivers=4)

    for x in range(20, 26):
        tlc5947[x] = 1000
        tlc5947.write()
        time.sleep(0.5)
        tlc5947[x] = 0
        tlc5947.write()
        time.sleep(0.5)
Beispiel #9
0
    def __init__(self):
        threading.Thread.__init__(self)
        self.channels = [0] * 24
        spi = busio.SPI(clock=board.SCK, MOSI=board.MOSI)
        latch = digitalio.DigitalInOut(board.D26)
        self.tlc5947 = adafruit_tlc5947.TLC5947(spi, latch, num_drivers=3)
        for channel_number in range(len(self.channels)):
            self.channels[channel_number] = self.tlc5947.create_pwm_out(
                channel_number)
        self.queue = queue.Queue()
        self.all = Lights_Pattern(self.pattern_channels.ALL, self.queue)
        self.peso = Lights_Pattern(self.pattern_channels.PESO, self.queue)
        self.coco = Lights_Pattern(self.pattern_channels.COCO, self.queue)
        self.naranja = Lights_Pattern(self.pattern_channels.NARANJA,
                                      self.queue)
        self.mango = Lights_Pattern(self.pattern_channels.MANGO, self.queue)
        self.sandia = Lights_Pattern(self.pattern_channels.SANDIA, self.queue)
        self.pina = Lights_Pattern(self.pattern_channels.PINA, self.queue)
        self.spoke_1 = Lights_Pattern(self.pattern_channels.SPOKE_1,
                                      self.queue)
        self.spoke_2 = Lights_Pattern(self.pattern_channels.SPOKE_2,
                                      self.queue)
        self.spoke_3 = Lights_Pattern(self.pattern_channels.SPOKE_3,
                                      self.queue)
        self.spoke_4 = Lights_Pattern(self.pattern_channels.SPOKE_4,
                                      self.queue)
        self.spoke_5 = Lights_Pattern(self.pattern_channels.SPOKE_5,
                                      self.queue)
        self.spoke_6 = Lights_Pattern(self.pattern_channels.SPOKE_6,
                                      self.queue)
        self.spoke_7 = Lights_Pattern(self.pattern_channels.SPOKE_7,
                                      self.queue)
        self.spoke_8 = Lights_Pattern(self.pattern_channels.SPOKE_8,
                                      self.queue)
        self.spoke_9 = Lights_Pattern(self.pattern_channels.SPOKE_9,
                                      self.queue)
        self.spoke_10 = Lights_Pattern(self.pattern_channels.SPOKE_10,
                                       self.queue)
        self.ripple_naranja_1 = Lights_Pattern(
            self.pattern_channels.RIPPLE_NARANJA_1, self.queue)
        self.ripple_naranja_2 = Lights_Pattern(
            self.pattern_channels.RIPPLE_NARANJA_2, self.queue)
        self.ripple_naranja_3 = Lights_Pattern(
            self.pattern_channels.RIPPLE_NARANJA_3, self.queue)
        self.ripple_naranja_4 = Lights_Pattern(
            self.pattern_channels.RIPPLE_NARANJA_4, self.queue)
        self.ripple_naranja_5 = Lights_Pattern(
            self.pattern_channels.RIPPLE_NARANJA_5, self.queue)
        self.ripple_mango_1 = Lights_Pattern(
            self.pattern_channels.RIPPLE_MANGO_1, self.queue)
        self.ripple_mango_2 = Lights_Pattern(
            self.pattern_channels.RIPPLE_MANGO_2, self.queue)
        self.ripple_mango_3 = Lights_Pattern(
            self.pattern_channels.RIPPLE_MANGO_3, self.queue)
        self.ripple_mango_4 = Lights_Pattern(
            self.pattern_channels.RIPPLE_MANGO_4, self.queue)
        self.ripple_mango_5 = Lights_Pattern(
            self.pattern_channels.RIPPLE_MANGO_5, self.queue)
        self.ripple_sandia_1 = Lights_Pattern(
            self.pattern_channels.RIPPLE_SANDIA_1, self.queue)
        self.ripple_sandia_2 = Lights_Pattern(
            self.pattern_channels.RIPPLE_SANDIA_2, self.queue)
        self.ripple_sandia_3 = Lights_Pattern(
            self.pattern_channels.RIPPLE_SANDIA_3, self.queue)
        self.ripple_sandia_4 = Lights_Pattern(
            self.pattern_channels.RIPPLE_SANDIA_4, self.queue)
        self.ripple_sandia_5 = Lights_Pattern(
            self.pattern_channels.RIPPLE_SANDIA_5, self.queue)
        self.ripple_pina_1 = Lights_Pattern(
            self.pattern_channels.RIPPLE_PINA_1, self.queue)
        self.ripple_pina_2 = Lights_Pattern(
            self.pattern_channels.RIPPLE_PINA_2, self.queue)
        self.ripple_pina_3 = Lights_Pattern(
            self.pattern_channels.RIPPLE_PINA_3, self.queue)
        self.ripple_pina_4 = Lights_Pattern(
            self.pattern_channels.RIPPLE_PINA_4, self.queue)
        self.ripple_pina_5 = Lights_Pattern(
            self.pattern_channels.RIPPLE_PINA_5, self.queue)
        self.ripple_coco_1 = Lights_Pattern(
            self.pattern_channels.RIPPLE_COCO_1, self.queue)
        self.ripple_coco_2 = Lights_Pattern(
            self.pattern_channels.RIPPLE_COCO_2, self.queue)
        self.ripple_coco_3 = Lights_Pattern(
            self.pattern_channels.RIPPLE_COCO_3, self.queue)
        self.ripple_coco_4 = Lights_Pattern(
            self.pattern_channels.RIPPLE_COCO_4, self.queue)
        self.ripple_coco_5 = Lights_Pattern(
            self.pattern_channels.RIPPLE_COCO_5, self.queue)
        self.inner_circle = Lights_Pattern(self.pattern_channels.INNER_CIRCLE,
                                           self.queue)
        self.outer_circle = Lights_Pattern(self.pattern_channels.OUTER_CIRCLE,
                                           self.queue)
        self.serpentine_edge_coco = Lights_Pattern(
            self.pattern_channels.SERPENTINE_EDGE_COCO, self.queue)
        self.serpentine_edge_naranja = Lights_Pattern(
            self.pattern_channels.SERPENTINE_EDGE_NARANJA, self.queue)
        self.serpentine_edge_mango = Lights_Pattern(
            self.pattern_channels.SERPENTINE_EDGE_MANGO, self.queue)
        self.serpentine_edge_sandia = Lights_Pattern(
            self.pattern_channels.SERPENTINE_EDGE_SANDIA, self.queue)
        self.serpentine_edge_pina = Lights_Pattern(
            self.pattern_channels.SERPENTINE_EDGE_PINA, self.queue)

        self.serpentine_center_coco = Lights_Pattern(
            self.pattern_channels.SERPENTINE_CENTER_COCO, self.queue)
        self.serpentine_center_naranja = Lights_Pattern(
            self.pattern_channels.SERPENTINE_CENTER_NARANJA, self.queue)
        self.serpentine_center_mango = Lights_Pattern(
            self.pattern_channels.SERPENTINE_CENTER_MANGO, self.queue)
        self.serpentine_center_sandia = Lights_Pattern(
            self.pattern_channels.SERPENTINE_CENTER_SANDIA, self.queue)
        self.serpentine_center_pina = Lights_Pattern(
            self.pattern_channels.SERPENTINE_CENTER_PINA, self.queue)

        self.channel_0 = Lights_Pattern(self.pattern_channels.CHANNEL_0,
                                        self.queue)
        self.channel_1 = Lights_Pattern(self.pattern_channels.CHANNEL_1,
                                        self.queue)
        self.channel_2 = Lights_Pattern(self.pattern_channels.CHANNEL_2,
                                        self.queue)
        self.channel_3 = Lights_Pattern(self.pattern_channels.CHANNEL_3,
                                        self.queue)
        self.channel_4 = Lights_Pattern(self.pattern_channels.CHANNEL_4,
                                        self.queue)
        self.channel_5 = Lights_Pattern(self.pattern_channels.CHANNEL_5,
                                        self.queue)
        self.channel_6 = Lights_Pattern(self.pattern_channels.CHANNEL_6,
                                        self.queue)
        self.channel_7 = Lights_Pattern(self.pattern_channels.CHANNEL_7,
                                        self.queue)
        self.channel_8 = Lights_Pattern(self.pattern_channels.CHANNEL_8,
                                        self.queue)
        self.channel_9 = Lights_Pattern(self.pattern_channels.CHANNEL_9,
                                        self.queue)
        self.channel_10 = Lights_Pattern(self.pattern_channels.CHANNEL_10,
                                         self.queue)
        self.channel_11 = Lights_Pattern(self.pattern_channels.CHANNEL_11,
                                         self.queue)
        self.channel_12 = Lights_Pattern(self.pattern_channels.CHANNEL_12,
                                         self.queue)
        self.channel_13 = Lights_Pattern(self.pattern_channels.CHANNEL_13,
                                         self.queue)
        self.channel_14 = Lights_Pattern(self.pattern_channels.CHANNEL_14,
                                         self.queue)
        self.channel_15 = Lights_Pattern(self.pattern_channels.CHANNEL_15,
                                         self.queue)
        self.channel_16 = Lights_Pattern(self.pattern_channels.CHANNEL_16,
                                         self.queue)
        self.channel_17 = Lights_Pattern(self.pattern_channels.CHANNEL_17,
                                         self.queue)
        self.channel_18 = Lights_Pattern(self.pattern_channels.CHANNEL_18,
                                         self.queue)
        self.channel_19 = Lights_Pattern(self.pattern_channels.CHANNEL_19,
                                         self.queue)
        self.channel_20 = Lights_Pattern(self.pattern_channels.CHANNEL_20,
                                         self.queue)
        self.channel_21 = Lights_Pattern(self.pattern_channels.CHANNEL_21,
                                         self.queue)
        self.channel_22 = Lights_Pattern(self.pattern_channels.CHANNEL_22,
                                         self.queue)
        self.channel_23 = Lights_Pattern(self.pattern_channels.CHANNEL_23,
                                         self.queue)

        self.start()
Beispiel #10
0
# Try to create an SPI device
spi = busio.SPI(board.SCLK, board.MOSI, board.MISO)
# Initialize TLC5947
DRIVER_COUNT = 2  # change this to the number of drivers you have chained
LATCH = digitalio.DigitalInOut(board.CE0)

#tlc5947 = adafruit_tlc5947.TLC5947(spi, LATCH, num_drivers=DRIVER_COUNT)

# You can optionally disable auto_write which allows you to control when
# channel state is written to the chip.  Normally auto_write is true and
# will automatically write out changes as soon as they happen to a channel, but
# if you need more control or atomic updates of multiple channels then disable
# and manually call write as shown below.
tlc5947 = adafruit_tlc5947.TLC5947(spi,
                                   LATCH,
                                   num_drivers=DRIVER_COUNT,
                                   auto_write=False)

# There are two ways to set channel PWM values. The first is by getting
# a PWMOut object that acts like the built-in PWMOut and can be used anywhere
# it is used in your code.  Change the duty_cycle property to a 16-bit value
# (note this is NOT the 12-bit value supported by the chip natively) and the
# PWM channel will be updated.


def first_last():
    """Cycles the red pin of LED one up, then the other LED; now dims the LEDs
    both down. Repeats with green and blue pins. Then starts all over again.
    Hook up one RGB LED to pins 0 (red), 1 (green), and 2 (blue), AND connect
    another RGB LED to pins 21, 22 and 23 of the last chained driver, respectively.
    """
Beispiel #11
0
def playMidi(song_name):
    mid = mido.MidiFile('midifiles/' + song_name)

    notesDict = {'songName': 'testname', 'bpm': 999, 'notes': []}
    tempo = 0
    length = 0
    notesArray = [[]]
    tickLength = 0

    SCK = board.SCK
    MOSI = board.MOSI
    LATCH = digitalio.DigitalInOut(board.D5)

    # Initialize SPI bus.
    spi = busio.SPI(clock=SCK, MOSI=MOSI)

    # Initialize TLC5947
    tlc5947 = adafruit_tlc5947.TLC5947(spi,
                                       LATCH,
                                       auto_write=False,
                                       num_drivers=4)
    for x in range(88):
        tlc5947[x] = 0
    tlc5947.write()

    for msg in mid:
        if msg.is_meta and msg.type == 'set_tempo':
            tempo = int(msg.tempo)
            length = int(
                floor(mido.second2tick(mid.length, mid.ticks_per_beat, tempo)))
            tickLength = mido.tick2second(1, mid.ticks_per_beat, tempo)
            break

    print('Tick length: ' + str(tickLength))
    currentTick = 0
    notesArray[0] = [0 for x in range(89)]
    lineIncrement = 0
    for msg in mid:
        #print(msg)
        if msg.type is 'note_on' or msg.type is 'note_off':
            delayAfter = int(
                floor(mido.second2tick(msg.time, mid.ticks_per_beat, tempo)))
            if delayAfter == 0:
                if msg.note < 89:
                    notesArray[lineIncrement][msg.note - 12] = msg.velocity
            else:
                notesArray[lineIncrement][88] = delayAfter
                notesArray.append([0 for x in range(89)])
                lineIncrement += 1
            """ Old code:
                for x in range (newNote['delayAfter']):
                    if x != 0:
                        notesArray[x+currentTick] = notesArray[x+currentTick-1]
                currentTick += newNote['delayAfter']
                
            notesArray[currentTick][newNote['note'] - 1] = newNote['velocity']
            # tlc5947.write()
            notesDict['notes'].append(newNote)
            """
    """
    with open('notes.json', 'w') as outfile:
        json.dump(notesDict, outfile)
    """

    startTime = time.time()
    tlc5947.write()
    time.sleep(3)
    for line in notesArray:
        """
        tlc5947[27] = 900
        tlc5947[68] = 4000
        tlc5947.write()
        time.sleep(2)
        tlc5947[27] = 0
        tlc5947[68] = 0
        tlc5947.write()
        time.sleep(2)
        """

        print(line)
        # send array to PWM IC
        for x in range(len(line) - 1):
            if line[x] != 0:
                tlc5947[x] = line[x] * 32
            else:
                tlc5947[x] = 0
        tlc5947.write()
        # time.sleep(tickLength)

        time.sleep(mido.tick2second(line[88], mid.ticks_per_beat, tempo) * 0.4)

        for x in range(88):
            tlc5947[x] = 0
        tlc5947.write()

        time.sleep(mido.tick2second(line[88], mid.ticks_per_beat, tempo) * 0.6)

    for x in range(88):
        tlc5947[x] = 0
    tlc5947.write()
import digitalio
import time
import adafruit_tlc5947

maxPwm = 4095

# Define pins connected to the TLC5947
SCK = board.SCK
MOSI = board.MOSI
LATCH = digitalio.DigitalInOut(board.D5)

# Initialize SPI bus.
spi = busio.SPI(clock=SCK, MOSI=MOSI)

# Initialize TLC5947
tlc5947 = adafruit_tlc5947.TLC5947(spi, LATCH, auto_write=False, num_drivers=4)


def test_all_keys():
    val = 4000
    zeroarray = [0] * 88
    for i in range(len(zeroarray)):
        tlc5947[i] = zeroarray[i]

    tlc5947.write()

    time.sleep(5)

    while 1:
        time.sleep(.5)
        tlc5947[0] = 2000
import board
import busio
import digitalio
import adafruit_tlc5947
import time
    
spi = busio.SPI(clock=board.SCK, MOSI=board.MOSI)
latch = digitalio.DigitalInOut(board.D26)
number_of_boards = 1
number_of_channels = number_of_boards * 24
tlc5947 = adafruit_tlc5947.TLC5947(spi, latch, num_drivers=number_of_boards)


pins = [0]*(number_of_channels)

for channel in range(len(pins)):
    pins[channel] = tlc5947.create_pwm_out(channel)

while True:
    for channel in range(number_of_channels):
        pins[channel].duty_cycle = 50000
        print("channel=", channel)
        time.sleep(.2)
        pins[channel].duty_cycle = 0

Beispiel #14
0
#!/usr/bin/env python3

# import RPi.GPIO as GPIO
import time
import spidev
import numpy as np

import adafruit_tlc5947

spi = spidev.SpiDev()
spi.open(0, 0)
led_values = np.array([0] * 24)

tlc5947 = adafruit_tlc5947.TLC5947(spi)


def push():
    mask = 0xF
    atoms = [x >> y & mask for x in led_values[::-1] for y in [8, 4, 0]]
    blocks = []
    for it in range(len(atoms) // 2):
        block = (atoms[it * 2] << 4) + atoms[it * 2 + 1]
        blocks = blocks + [int(block)]  # Aendern von np.int in int
    print(blocks)
    spi.xfer(blocks)


def set(led_nr, value):
    '''Setzen einer LED. Gültige Value Werte: 0 - 0xFFFD
    eingacher ist es die LED direkt über das Numpy Array zu setzen'''
    led_values[led_nr - 1] = value
Beispiel #15
0
# Will update channel values to different PWM duty cycles.
# Authors: Tony DiCola, Walter Haschka

import board
import busio
import digitalio

import adafruit_tlc5947

# Initialize SPI bus.
spi = busio.SPI(clock=board.SCK, MOSI=board.MOSI)

# Initialize TLC5947
DRIVER_COUNT = 2  # change this to the number of drivers you have chained
LATCH = digitalio.DigitalInOut(board.D5)
tlc5947 = adafruit_tlc5947.TLC5947(spi, LATCH, num_drivers=DRIVER_COUNT)

# You can optionally disable auto_write which allows you to control when
# channel state is written to the chip.  Normally auto_write is true and
# will automatically write out changes as soon as they happen to a channel, but
# if you need more control or atomic updates of multiple channels then disable
# and manually call write as shown below.
# tlc5947 = adafruit_tlc5947.TLC5947(spi, LATCH, num_drivers=DRIVER_COUNT, auto_write=False)

# There are two ways to set channel PWM values. The first is by getting
# a PWMOut object that acts like the built-in PWMOut and can be used anywhere
# it is used in your code.  Change the duty_cycle property to a 16-bit value
# (note this is NOT the 12-bit value supported by the chip natively) and the
# PWM channel will be updated.

import board
import busio
import digitalio

import adafruit_tlc5947

# Define pins connected to the TLC5947
SCK = board.SCK
MOSI = board.MOSI
LATCH = digitalio.DigitalInOut(board.D5)

# Initialize SPI bus.
spi = busio.SPI(clock=SCK, MOSI=MOSI)

# Initialize TLC5947
tlc5947 = adafruit_tlc5947.TLC5947(spi, LATCH)
# You can optionally disable auto_write which allows you to control when
# channel state is written to the chip.  Normally auto_write is true and
# will automatically write out changes as soon as they happen to a channel, but
# if you need more control or atomic updates of multiple channels then disable
# and manually call write as shown below.
# tlc5947 = adafruit_tlc5947.TLC5947(spi, LATCH, auto_write=False)

# There are two ways to channel channel PWM values.  The first is by getting
# a PWMOut object that acts like the built-in PWMOut and can be used anywhere
# it is used in your code.  Change the duty_cycle property to a 16-bit value
# (note this is NOT the 12-bit value supported by the chip natively) and the
# PWM channel will be updated.

# With an RGB LED hooked up to pins 0, 1, and 2, cycle the red, green, and
# blue pins up and down:
Beispiel #17
0
    def __init__(self):
        threading.Thread.__init__(self)
        self.channels = [0] * 72
        spi = busio.SPI(clock=board.SCK, MOSI=board.MOSI)
        latch = digitalio.DigitalInOut(board.D22)
        self.tlc5947 = adafruit_tlc5947.TLC5947(spi, latch, num_drivers=3)

        for channel_number in range(len(self.channels)):
            self.channels[channel_number] = self.tlc5947.create_pwm_out(
                channel_number)

        self.queue = queue.Queue()
        self.trail_rollover_right = Lights_Pattern(
            self.pattern_channels.TRAIL_ROLLOVER_RIGHT, self.queue)
        self.trail_rollover_left = Lights_Pattern(
            self.pattern_channels.TRAIL_ROLLOVER_LEFT, self.queue)
        self.trail_sling_right = Lights_Pattern(
            self.pattern_channels.TRAIL_SLING_RIGHT, self.queue)
        self.trail_sling_left = Lights_Pattern(
            self.pattern_channels.TRAIL_SLING_LEFT, self.queue)
        self.trail_pop_left = Lights_Pattern(
            self.pattern_channels.TRAIL_POP_LEFT, self.queue)
        self.trail_pop_right = Lights_Pattern(
            self.pattern_channels.TRAIL_POP_RIGHT, self.queue)
        self.trail_pop_middle = Lights_Pattern(
            self.pattern_channels.TRAIL_POP_CENTER, self.queue)
        self.trail_spinner = Lights_Pattern(
            self.pattern_channels.TRAIL_SPINNER, self.queue)
        self.pie_rollover_right = Lights_Pattern(
            self.pattern_channels.PIE_ROLLOVER_RIGHT, self.queue)
        self.pie_rollover_left = Lights_Pattern(
            self.pattern_channels.PIE_ROLLOVER_LEFT, self.queue)
        self.pie_sling_right = Lights_Pattern(
            self.pattern_channels.PIE_SLING_RIGHT, self.queue)
        self.pie_sling_left = Lights_Pattern(
            self.pattern_channels.PIE_SLING_LEFT, self.queue)
        self.pie_pop_left = Lights_Pattern(self.pattern_channels.PIE_POP_LEFT,
                                           self.queue)
        self.pie_pop_right = Lights_Pattern(
            self.pattern_channels.PIE_POP_RIGHT, self.queue)
        self.pie_pop_middle = Lights_Pattern(
            self.pattern_channels.PIE_POP_CENTER, self.queue)
        self.pie_spinner = Lights_Pattern(self.pattern_channels.PIE_SPINNER,
                                          self.queue)
        self.pie = Lights_Pattern(self.pattern_channels.PIE, self.queue)
        self.ripple_1 = Lights_Pattern(self.pattern_channels.RIPPLE_1,
                                       self.queue)
        self.ripple_2 = Lights_Pattern(self.pattern_channels.RIPPLE_2,
                                       self.queue)
        self.ripple_3 = Lights_Pattern(self.pattern_channels.RIPPLE_3,
                                       self.queue)
        self.ripple_4 = Lights_Pattern(self.pattern_channels.RIPPLE_4,
                                       self.queue)
        self.ripple_5 = Lights_Pattern(self.pattern_channels.RIPPLE_5,
                                       self.queue)
        self.ripple_6 = Lights_Pattern(self.pattern_channels.RIPPLE_6,
                                       self.queue)
        self.ripple_7 = Lights_Pattern(self.pattern_channels.RIPPLE_7,
                                       self.queue)
        self.ripple_8 = Lights_Pattern(self.pattern_channels.RIPPLE_8,
                                       self.queue)
        self.ripple_9 = Lights_Pattern(self.pattern_channels.RIPPLE_9,
                                       self.queue)
        self.ripple_10 = Lights_Pattern(self.pattern_channels.RIPPLE_10,
                                        self.queue)
        self.ripple_11 = Lights_Pattern(self.pattern_channels.RIPPLE_11,
                                        self.queue)
        self.ripple_12 = Lights_Pattern(self.pattern_channels.RIPPLE_12,
                                        self.queue)
        self.ripple_13 = Lights_Pattern(self.pattern_channels.RIPPLE_13,
                                        self.queue)
        self.ripple_14 = Lights_Pattern(self.pattern_channels.RIPPLE_14,
                                        self.queue)
        self.ripple_15 = Lights_Pattern(self.pattern_channels.RIPPLE_15,
                                        self.queue)
        self.ripple_16 = Lights_Pattern(self.pattern_channels.RIPPLE_16,
                                        self.queue)
        self.ripple_17 = Lights_Pattern(self.pattern_channels.RIPPLE_17,
                                        self.queue)
        self.ripple_18 = Lights_Pattern(self.pattern_channels.RIPPLE_18,
                                        self.queue)
        self.sign_arrow_left = Lights_Pattern(
            self.pattern_channels.SIGN_ARROW_LEFT, self.queue)
        self.sign_arrow_right = Lights_Pattern(
            self.pattern_channels.SIGN_ARROW_RIGHT, self.queue)
        self.sign_bottom_left = Lights_Pattern(
            self.pattern_channels.SIGN_BOTTOM_LEFT, self.queue)
        self.sign_bottom_right = Lights_Pattern(
            self.pattern_channels.SIGN_BOTTOM_RIGHT, self.queue)
        self.sign_top = Lights_Pattern(self.pattern_channels.SIGN_TOP,
                                       self.queue)
        self.all_radial = Lights_Pattern(self.pattern_channels.ALL_RADIAL,
                                         self.queue)
        #self.all_clockwise = Lights_Pattern(self.pattern_channels.ALL_CLOCKWISE, self.queue)
        self.start()
Beispiel #18
0
import time
'''
This program requires an image colormap.jpg to be put on the desktop of the pi. Creating this image involves:
    MS paint (or any other tool)
    resize the canvas to a ratio of imageheight : imagewidth
    paint in pure red or blue (255, 0, 0 or 0, 0, 255)
    ctrl A, reduce canvas size to imageheight * imagewidth
    save as colormap.jpg, transfer to pi via WinSCP
    
This program also assumes that a single chain of leds will be folded left and right multiple times to create a grid
https://www.adafruit.com/product/3635 is the LED strip this works with
'''

spi = busio.SPI(clock=board.SCK, MOSI=board.MOSI)
latch = digitalio.DigitalInOut(board.D5)
tlc5947 = adafruit_tlc5947.TLC5947(spi, latch)
'''
imageheight=9
imagewidth=10

os.chdir("/")

colormap = Image.open('home/pi/Desktop/colormap.jpg')
r, g, b = colormap.split()
red=r.load() # indexes from top left as origin, +y down, +x right, [x, y]


x=0
y=0
counter=0
import adafruit_tlc5947
import board
import busio
import digitalio
import time

SCK = board.SCK
MOSI = board.MOSI
LATCH = digitalio.DigitalInOut(board.D22)

number_of_boards = 3
number_of_channels = number_of_boards * 24

spi = busio.SPI(clock=SCK, MOSI=MOSI)

tlc5947 = adafruit_tlc5947.TLC5947(spi, LATCH, num_drivers=number_of_boards)

pins = [0] * (number_of_channels)

print("number of pins=", len(pins))

for channel in range(len(pins)):
    print(channel)
    pins[channel] = tlc5947.create_pwm_out(channel)

groups = {
    "TRAIL_ROLLOVER_RIGHT": [16, 15, 14, 13, 12],
    "TRAIL_ROLLOVER_LEFT": [19, 20, 21, 22, 23],
    "TRAIL_SLING_RIGHT": [11, 10, 9],
    "TRAIL_SLING_LEFT": [0, 1, 2],
    "TRAIL_POP_LEFT": [66, 65, 64, 63, 62, 61, 60],