示例#1
0
    def write_matrix(self, pin_list):
        if self.update_skip != 0:
            self.update_skip -= 1
            if self.update_skip >= 0:
                return

        self.led.all_off()

        if self.p_type == 'SBARS':
            for y in range(self.led_config.matrix_width):
                y_ind = int(
                    ((self.last + 1.0) / self.led_config.matrix_width) * y)
                for x_cord in range(
                        int(pin_list[y_ind] *
                            float(self.led_config.matrix_height))):
                    rgb = color_map[int(255.0 * float(x_cord) /
                                        float(self.led_config.matrix_height))]
                    self.led.set(x_cord, y_ind, rgb)
        if self.p_type == 'MBARS':
            norm_arr = [int(x * 255) for x in pin_list]
            self.drops.append(norm_arr)
            for y_cord in range(self.led_config.matrix_height):
                for x in range(self.led_config.matrix_width):
                    x_ind = int(
                        ((self.last + 1.0) / self.led_config.matrix_width) * x)
                    if self.drops[y_cord][x_ind] > 64:
                        rgb = scale(color_map[255 - self.drops[y_cord][x_ind]],
                                    int(self.drops[y_cord][x_ind] * 0.5))
                        self.led.set(x, y_cord, rgb)
            del self.drops[0]
        elif self.p_type == 'IMAGE':
            complete_image = Image.new("RGBA", self.images[0].size)
            for pin in xrange(len(pin_list)):
                if pin_list[pin] > 0.25:
                    complete_image = ImageChops.add_modulo(
                        complete_image,
                        ImageEnhance.Brightness(self.images[pin]).enhance(
                            pin_list[pin]))

            image.showImage(
                self.led, "",
                ImageEnhance.Brightness(complete_image).enhance(
                    self.max_brightness * 0.5))

        self.led.update()
        self.update_skip = self.skip
#col_time is time to display each vertical line for, in ms
if argc > 3:
    col_time = int(argv[3])

#bgcolor is the color that will be used on transparent pixels
if argc > 4:
    bgcolor = hex2rgb(argv[4])

#open the file so it is not loaded each time through
i = img.Image.open(file)

img_width = i.size[0]
totalFrameTime = img_width * col_time

print "Image Display Time: {0:.1f}s".format(totalFrameTime/1000.0)

driver = DriverSerial(LEDTYPE.LPD8806, num = 96, c_order=ChannelOrder.BRG, SPISpeed=16, gamma=gamma.LPD8806)
led = LEDPOV(driver, povHeight = 96, width = img_width, rotation=MatrixRotation.ROTATE_0, vert_flip=True)
led.setMasterBrightness(bright)

img.showImage(led, imageObj = i, bgcolor=bgcolor)

try:
    while True:
        led.update(frameTime=totalFrameTime)
except KeyboardInterrupt:
    led.all_off()
    led.update()

示例#3
0
    def write_matrix(self, pin_list):
        if self.update_skip != 0:
            self.update_skip -= 1
            if self.update_skip >= 0:
                return

        if len(self.led_config.matrix_pattern_type) == 1:
            self.p_type = self.led_config.matrix_pattern_type[0]
        else:
            for pin in xrange(len(pin_list)):
                self.beats += pin_list[pin] * (len(pin_list) /
                                               (pin + 1)) * 0.002
            if self.beats > self.led_config.beats:
                self.beats = 0
                self.p_num += 1
                if self.p_num >= len(self.led_config.matrix_pattern_type):
                    self.p_num = 0
            self.p_type = self.led_config.matrix_pattern_type[self.p_num]

        self.led.all_off()

        h = self.led_config.matrix_height
        w = self.led_config.matrix_width

        if self.p_type == 'SBARS':
            for y in range(h):
                y_ind = int((float(len(pin_list)) / h) * y)
                for x_cord in range(int(pin_list[y_ind] * float(w))):
                    rgb = color_map[int(255.0 * float(x_cord) / float(w))]
                    self.led.set(y_ind, x_cord, rgb)

        if self.p_type == 'MBARS':
            norm_arr = [int(x * 255) for x in pin_list]
            self.drops.append(norm_arr)
            for y_cord in range(w):
                for x in range(h):
                    x_ind = int((float(len(pin_list)) / h) * x)
                    if self.drops[y_cord][x_ind] > 64:
                        rgb = scale(color_map[255 - self.drops[y_cord][x_ind]],
                                    int(self.drops[y_cord][x_ind] * 0.5))
                        self.led.set(x, w - 1 - y_cord, rgb)
            del self.drops[0]

        elif self.p_type == 'IMAGE':
            complete_image = self.base_image
            for pin in xrange(len(pin_list)):
                if pin_list[pin] > 0.55:
                    complete_image = ImageChops.add_modulo(
                        complete_image,
                        ImageEnhance.Brightness(self.images[pin]).enhance(
                            pin_list[pin]))

            image.showImage(
                self.led, "",
                ImageEnhance.Brightness(complete_image).enhance(
                    self.max_brightness * 0.5))

        elif self.p_type == 'PINWHEEL':
            amt = 0

            for pin in xrange(len(pin_list)):
                amt += pin_list[pin] * (len(pin_list) / (pin + 1)) * 0.25
            amt = int(amt)

            pos = 0
            for x in range(h):
                c = colors.hue_helper(pos, self._len, self._step)
                self.led.drawLine(self._cX, self._cY, x, 0, c)
                pos += 1

            for y in range(w):
                c = colors.hue_helper(pos, self._len, self._step)
                self.led.drawLine(self._cX, self._cY, h - 1, y, c)
                pos += 1

            for x in range(h - 1, -1, -1):
                c = colors.hue_helper(pos, self._len, self._step)
                self.led.drawLine(self._cX, self._cY, x, w - 1, c)
                pos += 1

            for y in range(w - 1, -1, -1):
                c = colors.hue_helper(pos, self._len, self._step)
                self.led.drawLine(self._cX, self._cY, 0, y, c)
                pos += 1

            self._step += amt
            if (self._step >= 255):
                self._step = 0

        elif self.p_type == 'CBARS':
            midl = int(h / 2)
            for y in range(w):
                level = pin_list[int(
                    (y / float(w)) * float(self.led_config.led_channel_count))]
                brightness = int(255 * level)
                rgb = scale(color_map[brightness], brightness)
                mlvl = int(level * midl)
                self.led.drawLine(midl - mlvl, y, midl + mlvl, y, rgb)

        elif self.p_type == 'CIRCLES':
            for pin in xrange(len(pin_list)):
                rgb = self.rgb[pin]
                c = scale(rgb, int((pin_list[pin]) * 255))
                self.led.drawCircle(self._cX, self._cY, pin, c)

        self.led.update()
        self.update_skip = self.skip
示例#4
0
from bibliopixel.drivers.serial_driver import *
from bibliopixel.led import *
import bibliopixel.image as image

coords1 = mapGen(50, 13)
coords2 = mapGen(50, 12)
bibliopixel.log.setLogLevel(bibliopixel.log.DEBUG)
driver1 = DriverSerial(num=650, type=LEDTYPE.WS2811, deviceID=1)
driver2 = DriverSerial(num=600, type=LEDTYPE.WS2811, deviceID=2)
led1 = LEDMatrix(driver1,
                 width=50,
                 height=13,
                 coordMap=coords1,
                 rotation=MatrixRotation.ROTATE_0,
                 masterBrightness=100,
                 pixelSize=(1, 1))
led2 = LEDMatrix(driver2,
                 width=50,
                 height=12,
                 coordMap=coords2,
                 rotation=MatrixRotation.ROTATE_0,
                 masterBrightness=100,
                 pixelSize=(1, 1))

image.showImage(led1, "c:\\users\\ztech\\pictures\\bill2.jpg", offset=(12, 0))
image.showImage(led2,
                "c:\\users\\ztech\\pictures\\bill2.jpg",
                offset=(12, -12))
led1.update()
led2.update()