コード例 #1
0
ファイル: led.py プロジェクト: wausaujs/IoT-lights
def fill(pixels, color=(255,255,255)):
    for i in range(pixels.count()):
        pixels.set_pixel(i, Adafruit_WS2801.RGB_to_color(color[0], color[1], color[2]))

    pixels.show()
コード例 #2
0
# Simple demo of of the WS2801/SPI-like addressable RGB LED lights.
import time
import RPi.GPIO as GPIO
import random

# Import the WS2801 module.
import Adafruit_WS2801
import Adafruit_GPIO.SPI as SPI

# Configure the count of pixels:
PIXEL_COUNT = 48
PIXEL_CLOCK = 11
PIXEL_DOUT = 10
pixels = Adafruit_WS2801.WS2801Pixels(PIXEL_COUNT,
                                      clk=PIXEL_CLOCK,
                                      do=PIXEL_DOUT)

#new functions
#colour lists and functions
coloor = {'r': 255, 'g': 0, 'b': 0}

#define pallette to be used
palette = 'xmascolours'

#create a list of tuples, each one defining two shades of base colours: red, orange, yellow, green purple and blue, we then randomly select from this to produce a random
#colour palette that is also distinctive
listcolours = [
    (178, 31, 53),
    (216, 39, 53),
    (255, 116, 53),
    (255, 203, 53),
コード例 #3
0
ファイル: player.py プロジェクト: frostblooded/1d_game
 def draw(self, pixels):
     red = math.ceil((self.__health - 1) * 255 // self.MAX_HEALTH)
     green = math.ceil((self.__health - 1) * 255 // self.MAX_HEALTH)
     blue = math.ceil((self.__health - 1) * 255 // self.MAX_HEALTH)
     pixels.set_pixel(self.get_current_position(),
                      Adafruit_WS2801.RGB_to_color(255, green, blue))
コード例 #4
0
class LedsPhysical:
    red = Adafruit_WS2801.RGB_to_color(255, 0, 0)
    green = Adafruit_WS2801.RGB_to_color(0, 255, 0)
    blue = Adafruit_WS2801.RGB_to_color(0, 0, 255)
    white = Adafruit_WS2801.RGB_to_color(255, 255, 255)
    yellow = Adafruit_WS2801.RGB_to_color(255, 255, 0)
    black = Adafruit_WS2801.RGB_to_color(0, 0, 0)

    def __init__(self):
        #      -------
        #      |* * *|
        # -----------------
        # * * *|* * *|* * *
        # -----------------
        #
        #      |3 4 5|
        # -------------------
        # 0 1 2 6 7 8 9 10 11
        # -------------------
        self.count = 12
        self.front_panel = [LedsPhysical.black] * 6
        self.left_panel = [LedsPhysical.black] * 3
        self.right_panel = [LedsPhysical.black] * 3
        self.pixels = Adafruit_WS2801.WS2801Pixels(self.count,
                                                   spi=SPI.SpiDev(0, 0),
                                                   gpio=GPIO)

    def __enter__(self):
        pass

    def __exit__(self, exc_type, exc_value, traceback):
        self.close()

    def close(self):
        pass

    def display(self):
        nested_output = self.left_panel + self.front_panel + self.right_panel
        for n, item in enumerate(nested_output):
            self.pixels.set_pixel(n, item)
        self.pixels.show()

    def set_front_panel(self, panel_list):
        if len(panel_list) == 6:
            self.front_panel = panel_list
        else:
            print("Warning - ignoring incorrect panel parameter %s" %
                  panel_list)
        self.display()

    def set_front_panel_item(self, front_panel_position, colour):
        """Front panel:
        top row: 0 1 2
        next row: 3 4 5
        
        Colour is tuple r,g,b
        """
        self.front_panel[front_panel_position] = colour
        self.display()

    def set_left_panel(self, panel_list):
        if len(panel_list) == 3:
            self.left_panel = panel_list
        else:
            print("Warning - ignoring incorrect panel parameter %s" %
                  panel_list)
        self.display()

    def set_right_panel(self, panel_list):
        if len(panel_list) == 3:
            self.right_panel = panel_list
        else:
            print("Warning - ignoring incorrect panel parameter %s" %
                  panel_list)
        self.display()

    def clear_all(self):
        self.front_panel = [LedsPhysical.black] * 6
        self.left_panel = [LedsPhysical.black] * 3
        self.right_panel = [LedsPhysical.black] * 3
        self.display()
コード例 #5
0
 def ws2801_all(self, r, g, b):
     pixels.clear()
     for x in range(PIXEL_COUNT):
         pixels.set_pixel(x, Adafruit_WS2801.RGB_to_color(r, g, b))
     pixels.show()
コード例 #6
0
 def lighton(self, brightness):
     for i in range(self.PIXEL_COUNT):
         self.pixels.set_pixel(i, Adafruit_WS2801.RGB_to_color(int(255*brightness), int(200*brightness), int(150*brightness)))
     self.pixels.show()
コード例 #7
0
ファイル: pi_ws2801.py プロジェクト: quidryan/pumpkinpi
SENSOR_PORT = 18

GPIO.setmode(GPIO.BCM)
GPIO.setup(SENSOR_PORT, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)

sensor_current = False
sensor_previous = False

# Configure the count of pixels:
PIXEL_COUNT = 9

# Alternatively specify a hardware SPI connection on /dev/spidev0.0:
SPI_PORT = 0
SPI_DEVICE = 0
pixels = Adafruit_WS2801.WS2801Pixels(PIXEL_COUNT,
                                      spi=SPI.SpiDev(SPI_PORT, SPI_DEVICE),
                                      gpio=GPIO)

redRGB = webcolors.name_to_rgb('red')
orangeRGB = webcolors.name_to_rgb('orange')


def flash_face(pixels, lefteye, righteye, mouth, blink_times=20):
    for i in range(blink_times):
        # blink two times, then wait
        pixels.clear()
        face(pixels, lefteye, righteye, mouth)
        time.sleep(0.5)

        pixels.clear()
        pixels.show()
コード例 #8
0
def xmas_two_party(wait=0.001):
    for i in range(pixels.count()):
        ga_Listening()
        ga_Responding()
        phone_Ring(pixels)
        pixels.set_pixel(i, Adafruit_WS2801.RGB_to_color(255, 0, 0))
        pixels.show()
        time.sleep(1)
        pixels.set_pixel(i, Adafruit_WS2801.RGB_to_color(0, 255, 0))
        pixels.show()
        time.sleep(1)
        ga_Listening()
        ga_Responding()
        phone_Ring(pixels)
        pixels.set_pixel(i, Adafruit_WS2801.RGB_to_color(255, 0, 0))
        pixels.show()
        time.sleep(1)
        pixels.set_pixel(i, Adafruit_WS2801.RGB_to_color(0, 255, 0))
        pixels.show()
        time.sleep(1)
        ga_Listening()
        ga_Responding()
        phone_Ring(pixels)
        pixels.set_pixel(i, Adafruit_WS2801.RGB_to_color(255, 0, 0))
        pixels.show()
        time.sleep(1)
        pixels.set_pixel(i, Adafruit_WS2801.RGB_to_color(0, 255, 0))
        pixels.show()
        time.sleep(1)
        ga_Listening()
        ga_Responding()
        phone_Ring(pixels)
        pixels.set_pixel(i, Adafruit_WS2801.RGB_to_color(255, 0, 0))
        pixels.show()
        time.sleep(1)
        pixels.set_pixel(i, Adafruit_WS2801.RGB_to_color(0, 255, 0))
        pixels.show()
        time.sleep(1)
        ga_Listening()
        ga_Responding()
        phone_Ring(pixels)
        pixels.set_pixel(i, Adafruit_WS2801.RGB_to_color(255, 0, 0))
        pixels.show()
        time.sleep(1)
        pixels.set_pixel(i, Adafruit_WS2801.RGB_to_color(0, 255, 0))
        pixels.show()
        time.sleep(1)
        ga_Listening()
        ga_Responding()
        phone_Ring(pixels)
        pixels.set_pixel(i, Adafruit_WS2801.RGB_to_color(255, 0, 0))
        pixels.show()
        time.sleep(1)
        pixels.set_pixel(i, Adafruit_WS2801.RGB_to_color(0, 255, 0))
        pixels.show()
        time.sleep(1)
    if wait > 0.0:
        time.sleep(wait)
コード例 #9
0
ファイル: ledcontrol.py プロジェクト: rmvanda/ledcontrols
 def color(self, rgb, g=False, b=False):
     if g is not False and b is not False:
         return Adafruit_WS2801.RGB_to_color(b, g, rgb)
     else:
         return Adafruit_WS2801.RGB_to_color(rgb[2], rgb[1], rgb[0])
コード例 #10
0
ファイル: bullet.py プロジェクト: frostblooded/1d_game
 def get_color(self):
     return Adafruit_WS2801.RGB_to_color(150, 150, 0)
コード例 #11
0
import Adafruit_WS2801
import Adafruit_GPIO.SPI as SPI
import datetime
import time
import urllib
import os

light_sensor_port = 40
GPIO.setmode(GPIO.BOARD)
GPIO.setup(light_sensor_port, GPIO.IN)

PIXEL_COUNT = 114
SPI_PORT = 0
SPI_DEVICE = 0
pixels = Adafruit_WS2801.WS2801Pixels(PIXEL_COUNT,
                                      spi=SPI.SpiDev(SPI_PORT, SPI_DEVICE),
                                      gpio=GPIO)

color_white_bright = Adafruit_WS2801.RGB_to_color(200, 200, 200)
color_white_dark = Adafruit_WS2801.RGB_to_color(30, 30, 30)
color_green = Adafruit_WS2801.RGB_to_color(0, 128, 0)
color_red = Adafruit_WS2801.RGB_to_color(139, 0, 0)

dot_top_left = 11
dot_bottom_left = 0
dot_bottom_right = 102
dot_top_right = 113

word_es = [10, 12]
word_ist = [32, 51, 52]
word_vor = [7, 15, 28]
コード例 #12
0
 def __init__(self, SPI_PORT = 0, SPI_DEVICE = 0, PIXEL_COUNT = 14):
     self.pixels = Adafruit_WS2801.WS2801Pixels(PIXEL_COUNT, spi=SPI.SpiDev(SPI_PORT, SPI_DEVICE))
     self.clear()
コード例 #13
0
import Adafruit_GPIO.SPI as SPI
import RPi.GPIO as GPIO
import time
import requests

#### Configuration ####

PIXEL_COUNT = 96

lights = { '1': [0, 1, 2] }

clientId = 'ID1234'
base_url = 'https://10398rsvyj.execute-api.us-west-2.amazonaws.com/prod'

# Light color for when all builds are successful
success_color = Adafruit_WS2801.RGB_to_color(0, 200, 0)

# Light color for when a light shows a build failure
failure_color = Adafruit_WS2801.RGB_to_color(200, 0, 0)

# Light color when we can't get the status of the lights
connection_error_color = Adafruit_WS2801.RGB_to_color(200, 200, 0)

status_url = base_url + '/lights/status'

SPI_PORT   = 0
SPI_DEVICE = 0

#### END Configuration ####

pixels = Adafruit_WS2801.WS2801Pixels(PIXEL_COUNT, spi=SPI.SpiDev(SPI_PORT, SPI_DEVICE), gpio=GPIO)
コード例 #14
0
def turn_off():
    for i in range(0, PIXEL_N):
        color = Adafruit_WS2801.RGB_to_color(0,0,0)
        pixels.set_pixel(i, color)
    pixels.show()
コード例 #15
0
ファイル: pi_ws2801.py プロジェクト: quidryan/pumpkinpi
def speak(pixels, eyes, mouth):
    eyecolor = Adafruit_WS2801.RGB_to_color(eyes[0], eyes[1], eyes[2])
    pixels.set_pixel(pixels.count() - 1, eyecolor)
    pixels.set_pixel(pixels.count() - 2, eyecolor)

    mouthcolor = Adafruit_WS2801.RGB_to_color(mouth[0], mouth[1], mouth[2])
コード例 #16
0
 def get_color(self):
     if self.active:
         return Adafruit_WS2801.RGB_to_color(0, 255, 0)
     else:
         return Adafruit_WS2801.RGB_to_color(0, 5, 0)
コード例 #17
0
def blinkDrum(drum):
    for k in range(drum.startLED, drum.endLED):
        pixels.set_pixel(
            k,
            Adafruit_WS2801.RGB_to_color(drum.color[0], drum.color[1],
                                         drum.color[2]))
コード例 #18
0
ファイル: single.py プロジェクト: mitche50/nanoxmastree
def test_pixels(pixels, selected):
    for i in range(pixels.count()):
        pixels.set_pixel(i, Adafruit_WS2801.RGB_to_color(89, 17, 88))
        pixels.show()
        print(i)
        time.sleep(2)
コード例 #19
0
def digital_clock_horizontal(timer_value=1,
                             timer_unit="minutes",
                             display_on_lights_bool=0):

    import numpy as np
    import time
    import math
    import os

    if display_on_lights_bool == 1:
        import Adafruit_WS2801
        import Adafruit_GPIO.SPI as SPI
        import RPi.GPIO as GPIO

    try:
        GPIO.setmode(GPIO.BCM)
        GPIO.setup(12, GPIO.OUT)
        GPIO.setup(16, GPIO.OUT)
        GPIO.output(16, GPIO.HIGH)
        GPIO.output(12, GPIO.LOW)
    except Exception as ex:
        print(ex)
        print("Error Encountered")

    if display_on_lights_bool == 1:
        PIXEL_COUNT = 160
        PIXEL_CLOCK = 11
        PIXEL_DOUT = 10
        pixels = Adafruit_WS2801.WS2801Pixels(PIXEL_COUNT,
                                              clk=PIXEL_CLOCK,
                                              do=PIXEL_DOUT)
        pixels.clear()
        pixels.show()

        #RBG
        hour_color = Adafruit_WS2801.RGB_to_color(0, 255, 0)  #blue
        minute_color = Adafruit_WS2801.RGB_to_color(255, 50, 255)  #yellow
        second_color = Adafruit_WS2801.RGB_to_color(255, 255, 0)  #magenta
        if timer_unit == "seconds":
            timer_color = Adafruit_WS2801.RGB_to_color(50, 0, 255)  #green
        elif timer_unit == "minutes":
            timer_color = Adafruit_WS2801.RGB_to_color(255, 0, 0)  #red
        elif timer_unit == "hours":
            timer_color = Adafruit_WS2801.RGB_to_color(200, 255, 0)  #purple
        else:
            print("Error getting timer color")
            exit()

    number_one = [[0, 1], [1, 0], [1, 1], [2, 1], [3, 1], [4, 0], [4, 1],
                  [4, 2]]
    number_two = [[0, 0], [0, 1], [0, 2], [1, 2], [2, 0], [2, 1], [2, 2],
                  [3, 0], [4, 0], [4, 1], [4, 2]]
    number_three = [[0, 0], [0, 1], [0, 2], [1, 2], [2, 0], [2, 1], [2, 2],
                    [3, 2], [4, 0], [4, 1], [4, 2]]
    number_four = [[0, 0], [0, 2], [1, 0], [1, 2], [2, 0], [2, 1], [2, 2],
                   [3, 2], [4, 2]]
    number_five = [[0, 0], [0, 1], [0, 2], [1, 0], [2, 0], [2, 1], [2, 2],
                   [3, 2], [4, 0], [4, 1], [4, 2]]
    number_six = [[0, 0], [0, 1], [0, 2], [1, 0], [2, 0], [2, 1], [2, 2],
                  [3, 0], [3, 2], [4, 0], [4, 1], [4, 2]]
    number_seven = [[0, 0], [0, 1], [0, 2], [1, 0], [1, 2], [2, 2], [3, 2],
                    [4, 2]]
    number_eight = [[0, 0], [0, 1], [0, 2], [1, 0], [1, 2], [2, 0], [2, 1],
                    [2, 2], [3, 0], [3, 2], [4, 0], [4, 1], [4, 2]]
    number_nine = [[0, 0], [0, 1], [0, 2], [1, 0], [1, 2], [2, 0], [2, 1],
                   [2, 2], [3, 2], [4, 2]]
    number_zero = [[0, 0], [0, 1], [0, 2], [1, 0], [1, 2], [2, 0], [2, 2],
                   [3, 0], [3, 2], [4, 0], [4, 1], [4, 2]]

    def print_timer(grid, seconds_remaining, timer_unit):

        #Get the timer value

        if timer_unit == "seconds":
            timer = math.ceil(seconds_remaining)
        elif timer_unit == "minutes":
            timer = math.ceil(seconds_remaining / 60)
        elif timer_unit == "hours":
            timer = math.ceil(seconds_remaining / (60 * 24))
        else:
            print("Error getting timer")
            exit()

        ## Check if timer entered new unit (e.g. minutes -> seconds), then change the unit and the value. Like going from 1 minute to 59 seconds.
        if timer_unit == "hours" and (seconds_remaining / (60 * 24)) < 1:
            timer = math.ceil(seconds_remaining / 60)
            timer_unit = "minutes"
            if display_on_lights_bool == 1:
                timer_color = Adafruit_WS2801.RGB_to_color(255, 0, 0)  #red
        if timer_unit == "minutes" and (seconds_remaining / 60) < 1:
            timer = math.ceil(seconds_remaining)
            timer_unit = "seconds"
            if display_on_lights_bool == 1:
                timer_color = Adafruit_WS2801.RGB_to_color(50, 0, 255)  #green

        if timer > 9:
            digit_seven = math.floor(timer / 10)
        else:
            digit_seven = math.floor(timer / 10)

        digit_eight = timer % 10

        digit_list = [digit_seven, digit_eight]

        for value in range(len(digit_list)):
            digit = digit_list[value]
            if digit == 1:
                digit_list[value] = number_one
            elif digit == 2:
                digit_list[value] = number_two
            elif digit == 3:
                digit_list[value] = number_three
            elif digit == 4:
                digit_list[value] = number_four
            elif digit == 5:
                digit_list[value] = number_five
            elif digit == 6:
                digit_list[value] = number_six
            elif digit == 7:
                digit_list[value] = number_seven
            elif digit == 8:
                digit_list[value] = number_eight
            elif digit == 9:
                digit_list[value] = number_nine
            else:
                if value % 2 != 0:
                    digit_list[value] = number_zero
                else:
                    digit_list[value] = [
                    ]  #prevents us from printing a zero for the most significant digit

        for index in digit_list[0]:  #digit 7  (timer)
            index = [index[0] + 5, index[1] + 9]
            grid[index[0], index[1]] = 4
            if display_on_lights_bool == 1:
                pixels.set_pixel(index[1] + (16 * index[0]), timer_color)
        for index in digit_list[1]:
            index = [index[0] + 5, index[1] + 13]
            grid[index[0], index[1]] = 4
            if display_on_lights_bool == 1:
                pixels.set_pixel(index[1] + (16 * index[0]), timer_color)

        return (grid, timer, timer_unit)

    def print_big_clock(grid):

        ## Get the time
        current_time = time.localtime()
        hour = current_time.tm_hour
        minute = current_time.tm_min
        second = current_time.tm_sec

        ## Get the numbers to print. Stored in digit_one, digit_two .... digit_six
        if hour > 9:
            digit_one = 1
        else:
            digit_one = 0
        digit_two = hour % 10
        if minute > 9:
            digit_three = math.floor(minute / 10)
        else:
            digit_three = 0
        digit_four = minute % 10
        if second > 9:
            digit_five = math.floor(second / 10)
        else:
            digit_five = 0
        digit_six = second % 10

        digit_list = [
            digit_one, digit_two, digit_three, digit_four, digit_five,
            digit_six
        ]

        for value in range(len(digit_list)):
            digit = digit_list[value]
            if digit == 1:
                digit_list[value] = number_one
            elif digit == 2:
                digit_list[value] = number_two
            elif digit == 3:
                digit_list[value] = number_three
            elif digit == 4:
                digit_list[value] = number_four
            elif digit == 5:
                digit_list[value] = number_five
            elif digit == 6:
                digit_list[value] = number_six
            elif digit == 7:
                digit_list[value] = number_seven
            elif digit == 8:
                digit_list[value] = number_eight
            elif digit == 9:
                digit_list[value] = number_nine
            else:
                if value % 2 != 0:
                    digit_list[value] = number_zero
                else:
                    digit_list[value] = [
                    ]  #prevents us from printing a zero for the most significant digit

        for index in digit_list[0]:  #digit one
            index = [
                index[0] + 0, index[1] + 0
            ]  #shift the upper left corner of the first hour digit to [0,0]
            grid[index[0], index[1]] = 1
            if display_on_lights_bool == 1:
                pixels.set_pixel(index[1] + (16 * index[0]), hour_color)
        for index in digit_list[1]:  #digit two
            index = [
                index[0] + 0, index[1] + 4
            ]  #shift the upper left corner of the second hour digit to [0,4], leaving a column between the digits
            grid[index[0], index[1]] = 1
            if display_on_lights_bool == 1:
                pixels.set_pixel(index[1] + (16 * index[0]), hour_color)
        for index in digit_list[2]:  #digit three
            index = [
                index[0] + 0, index[1] + 9
            ]  #shift the upper left corner of the first minute digit to [0,9], leaving two columns between the minute and hour
            grid[index[0], index[1]] = 2
            if display_on_lights_bool == 1:
                pixels.set_pixel(index[1] + (16 * index[0]), minute_color)
        for index in digit_list[3]:  #digit four
            index = [index[0] + 0, index[1] + 13]
            grid[index[0], index[1]] = 2
            if display_on_lights_bool == 1:
                pixels.set_pixel(index[1] + (16 * index[0]), minute_color)
        for index in digit_list[4]:  #digit 5 (seconds)
            index = [index[0] + 5, index[1] + 0]
            grid[index[0], index[1]] = 3
            if display_on_lights_bool == 1:
                pixels.set_pixel(index[1] + (16 * index[0]), second_color)
        for index in digit_list[5]:
            index = [index[0] + 5, index[1] + 4]
            grid[index[0], index[1]] = 3
            if display_on_lights_bool == 1:
                pixels.set_pixel(index[1] + (16 * index[0]), second_color)

        return (grid, hour, minute, second)

    [old_grid, hour, minute, second] = print_big_clock(np.zeros([10, 16]))

    if timer_value > 99 and timer_unit == "seconds":
        print("Invalid timer entry")
        exit()

    if timer_unit == "seconds":
        timer_end = time.time() + timer_value
    elif timer_unit == "minutes":
        timer_end = time.time() + (60 * timer_value)
    elif timer_unit == "hours":
        timer_end = time.time() + (24 * 60 * timer_value)
    else:
        print("Error getting timer_end")
        exit()

    while 1:

        [new_grid, hour, minute, second] = print_big_clock(np.zeros(
            [10,
             16]))  #Get the clock board state so we can check if it's changed

        seconds_remaining = timer_end - time.time()
        if seconds_remaining > 0:  #Check if the timer is done
            [new_grid, time_remaining,
             timer_unit] = print_timer(new_grid, seconds_remaining, timer_unit)
        elif seconds_remaining < 0 and (
            (seconds_remaining > -0.5) or
            (seconds_remaining > -1.5 and seconds_remaining < -1) or
            (seconds_remaining > -2.5 and seconds_remaining < -2) or
            (seconds_remaining > -3.5 and seconds_remaining < -3) or
            (seconds_remaining > -4.5 and seconds_remaining < -4)):
            for i in range(5, 10):
                for j in range(8, 16):
                    new_grid[i, j] = 8
                    if display_on_lights_bool == 1:
                        pixels.set_pixel(j + (16 * i), second_color)
            GPIO.output(12, GPIO.HIGH)
            GPIO.output(16, GPIO.HIGH)
        else:
            GPIO.output(12, GPIO.LOW)
            GPIO.output(16, GPIO.LOW)

        if (new_grid != old_grid).any(
        ):  #If it's true that new_grid != old_grid for any elements in the arrays (i.e. if the two arrays are different)...
            if display_on_lights_bool == 1:
                pixels.clear()

            [new_grid, hour, minute,
             second] = print_big_clock(np.zeros([10, 16]))
            if seconds_remaining > 0:  #redundant lines, but it resets the pixels after the clear
                [new_grid, time_remaining,
                 timer_unit] = print_timer(new_grid, seconds_remaining,
                                           timer_unit)

            old_grid = new_grid

            if minute == 0:  #Flash the light strands on the hour
                if display_on_lights_bool == 1:
                    GPIO.output(12, GPIO.HIGH)
                    GPIO.output(16, GPIO.HIGH)
                    time.sleep(1)
                    GPIO.output(12, GPIO.LOW)
                    GPIO.output(16, GPIO.LOW)
                    time.sleep(0.5)
                    GPIO.output(12, GPIO.HIGH)
                    GPIO.output(16, GPIO.HIGH)
                    time.sleep(1)
                    GPIO.output(12, GPIO.LOW)
                    GPIO.output(16, GPIO.LOW)

            print("Time is ", hour, minute, second)
            if seconds_remaining > 0:
                print("Timer value is: ", time_remaining, timer_unit)
            else:
                print("Timer done")

            #os.system('cls')
            print(new_grid)
            if display_on_lights_bool == 1:
                pixels.show()
コード例 #20
0
 def _RGB_to_color(self, rgb):
     # lib requires int
     r, g, b = self._get_rgb(rgb)
     # lib actually requires BGR instead of RGB
     return Adafruit_WS2801.RGB_to_color(int(b), int(g), int(r))
コード例 #21
0
    def print_timer(grid, seconds_remaining, timer_unit):

        #Get the timer value

        if timer_unit == "seconds":
            timer = math.ceil(seconds_remaining)
        elif timer_unit == "minutes":
            timer = math.ceil(seconds_remaining / 60)
        elif timer_unit == "hours":
            timer = math.ceil(seconds_remaining / (60 * 24))
        else:
            print("Error getting timer")
            exit()

        ## Check if timer entered new unit (e.g. minutes -> seconds), then change the unit and the value. Like going from 1 minute to 59 seconds.
        if timer_unit == "hours" and (seconds_remaining / (60 * 24)) < 1:
            timer = math.ceil(seconds_remaining / 60)
            timer_unit = "minutes"
            if display_on_lights_bool == 1:
                timer_color = Adafruit_WS2801.RGB_to_color(255, 0, 0)  #red
        if timer_unit == "minutes" and (seconds_remaining / 60) < 1:
            timer = math.ceil(seconds_remaining)
            timer_unit = "seconds"
            if display_on_lights_bool == 1:
                timer_color = Adafruit_WS2801.RGB_to_color(50, 0, 255)  #green

        if timer > 9:
            digit_seven = math.floor(timer / 10)
        else:
            digit_seven = math.floor(timer / 10)

        digit_eight = timer % 10

        digit_list = [digit_seven, digit_eight]

        for value in range(len(digit_list)):
            digit = digit_list[value]
            if digit == 1:
                digit_list[value] = number_one
            elif digit == 2:
                digit_list[value] = number_two
            elif digit == 3:
                digit_list[value] = number_three
            elif digit == 4:
                digit_list[value] = number_four
            elif digit == 5:
                digit_list[value] = number_five
            elif digit == 6:
                digit_list[value] = number_six
            elif digit == 7:
                digit_list[value] = number_seven
            elif digit == 8:
                digit_list[value] = number_eight
            elif digit == 9:
                digit_list[value] = number_nine
            else:
                if value % 2 != 0:
                    digit_list[value] = number_zero
                else:
                    digit_list[value] = [
                    ]  #prevents us from printing a zero for the most significant digit

        for index in digit_list[0]:  #digit 7  (timer)
            index = [index[0] + 5, index[1] + 9]
            grid[index[0], index[1]] = 4
            if display_on_lights_bool == 1:
                pixels.set_pixel(index[1] + (16 * index[0]), timer_color)
        for index in digit_list[1]:
            index = [index[0] + 5, index[1] + 13]
            grid[index[0], index[1]] = 4
            if display_on_lights_bool == 1:
                pixels.set_pixel(index[1] + (16 * index[0]), timer_color)

        return (grid, timer, timer_unit)
コード例 #22
0
class theLEDs(threading.Thread):

    # Configure the count of pixels:
    PIXEL_COUNT = 24

    runvar = True

    # Alternatively specify a hardware SPI connection on /dev/spidev0.0:
    SPI_PORT   = 0
    SPI_DEVICE = 0
    pixels = Adafruit_WS2801.WS2801Pixels(PIXEL_COUNT, spi=SPI.SpiDev(SPI_PORT, SPI_DEVICE), gpio=GPIO)

    comparesecond = 0
    t = 0

    nowdata = [1, 2, 3]

    config = {'status': None, 'brightness': None, 'show': None, 'r': None, 'g': None, 'b': None}

    json_file = "/opt/mycroft/skills/skill-my-alarm/settings.json"

    def __init__(self):
        threading.Thread.__init__(self)
        with open(self.json_file, 'r') as file:
            data = json.load(file)
            LED = data['LED']
            self.config['status'] = LED['status']
            self.config['brightness'] = float(LED['brightness'])
            self.config['show'] = LED['show']
            self.config['r'] = int(LED['r'])
            self.config['g'] = int(LED['g'])
            self.config['b'] = int(LED['b'])

    def config_led(self, config = {'status': None, 'brightness': None, 'show': None, 'r': None, 'g': None, 'b': None}):
        for c in self.config:
            if config[c] is not None:
                self.config[c] = config[c]
        json_data = None
        with open(self.json_file, 'r') as file:
            json_data = json.load(file)
            json_data['LED'] = self.config

        with open(self.json_file, 'w') as file:
            json.dump(json_data, file)

    def set_leds(self, number):
        highnumber = number/10
        lownumber = number%10

        leds = [[0, 0, 0, 0],[0, 0, 0, 0]]

        leds[0][3] = int(lownumber/8)
        leds[0][2] = int(lownumber%8/4)
        leds[0][1] = int(lownumber%8%4/2)
        leds[0][0] = int(lownumber%8%4%2/1)

        leds[1][0] = int(highnumber/8)
        leds[1][1] = int(highnumber%8/4)
        leds[1][2] = int(highnumber%8%4/2)
        leds[1][3] = int(highnumber%8%4%2/1)

        return leds

    def show(self, type, r, g, b, brightness):
        nowdata = [None, None, None]
        if type == 'time':
            now = datetime.datetime.now()
            nowdata = [now.second, now.minute, now.hour]

        elif type == 'date':
            now = datetime.datetime.now()
            nowdata = [now.year, now.month, now.day]

        else:
            return 0

        for k in range(len(nowdata)):
            leds = self.set_leds(nowdata[k])
            for i in range(len(leds)):
                for j in range(len(leds[i])):
                    if leds[i][j] == 1:
                        self.pixels.set_pixel(j+(k*8)+i*4, Adafruit_WS2801.RGB_to_color(int(r*brightness), int(g*brightness), int(b*brightness)))
                    else:
                        self.pixels.set_pixel(j+(k*8)+i*4, Adafruit_WS2801.RGB_to_color(0, 0, 0))

        self.pixels.show()

    def lighton(self, brightness):
        for i in range(self.PIXEL_COUNT):
            self.pixels.set_pixel(i, Adafruit_WS2801.RGB_to_color(int(255*brightness), int(200*brightness), int(150*brightness)))
        self.pixels.show()

    def off(self):
        self.pixels.clear()
        self.pixels.show()

    def run(self):
        self.pixels.clear()
        self.pixels.show()

        while True:
            while self.config['status']:
                if self.config['show'] == "time":
                    while self.config['show'] == "time":
                        self.show('time', self.config['r'],self.config['g'], self.config['b'], self.config['brightness'])
                        time.sleep(0.1)

                elif self.config['show'] == "date":
                    while self.config['show'] == "date":
                        self.show('date', self.config['r'],self.config['g'], self.config['b'], self.config['brightness'])
                        time.sleep(0.1)

                elif self.config['show'] == "light":
                    while self.config['show'] == "light":
                        self.lighton(self.config['brightness'])
                        time.sleep(0.1)

                elif self.config['show'] == "off":
                    self.off()
                    while self.config['show'] == "off":
                        pass

    def stop(self):
        self.config['show'] = 'off'
        self.off()
        GPIO.cleanup()
コード例 #23
0
ファイル: core.py プロジェクト: smoes/rambilight
    def run(self):

        """The rambilight algorithm is optimized to be fast but also offer a smooth
        experience. Some mechanics are implemented to due technical issues
        (e.g. bright spikes in picamera pictures.). If you do not have them u may
        adapt the algorithm.

        There are three concepts to guarantee a smooth experience:

        * The algorithm is based on shift-registers containing the last n values for each
        coordinate the colors are measured for. The colors in this register are averaged
        for cleaner experience. To prevent the mentioned bright spikes in the stream
        that let the LEDs flicker, `num_outliers` outliers are ignored (biggest distance to
        previous color).

        * Actual color values are transitioned over time. This means, that a color needs
        `fade_levels` steps to actually be displayed. This mechanism makes the light-switching
        in fast changing scenes less noisy.
 
        * Noise in the meaning of flickering (change delta sign rapidely) is punished by 
        tracking it. If the penalty is too high, only the former pixel is rendered.

        * The image is blurred in spots where the colors are measured in. The blurring
        is limited to these spots. This increases the performance drastically.
        Blurring averts very small changes in color due to camera noise, that result in
        distracting background noise.

        The algorithm runs with 30-40 fps on a raspberry pi rev. 3.
        """

        shift_register_length = 8

        num_outliers = 4
        fade_levels = 9

        blur_area = 6
        blur_strength = 10

        max_denoise_penalty = 20
        denoise_penalty_threshold = 3
        denoise_machine = [(0,0,(255,255,255))] * self.real_led_num

        registers = [[(255,255,255)] * shift_register_length] * self.real_led_num
        former_pixels = [(255,255,255)] * self.real_led_num

        while True:

            # check stopped/paused conditions before starting
            if self.stopped: break
            if self.paused:
                time.sleep(1)
                continue

            frame = self.stream.read()

            for (coord, led_num) in self.coordinates_to_led:

                # find the area that must be blurred and blur it.
                x_min = max(coord[1] - blur_area, 0)
                x_max = coord[1] + blur_area
                y_min = max(coord[0] - blur_area, 0)
                y_max = coord[0] + blur_area

                region = frame[x_min:x_max, y_min:y_max]
                pixel = np.mean(region, axis=(0,1))

                r = int(pixel[2])
                g = int(pixel[1])
                b = int(pixel[0])
               

                # extract former pixel
                former_r, former_g, former_b = former_pixels[led_num]

                if r < 22 and b < 22 and g < 22 and r+b+g < 55:
                    r,g,b = (0,0,0)

                # denoising
                (former_penalty_state, former_delta, (dr, dg, db)) = denoise_machine[led_num]
                delta = sign((r + g + b) - (former_r + former_g + former_b))
                penalty = former_delta != delta
                penalty_state = former_penalty_state + 5 if penalty else former_penalty_state - 1
                render_change = penalty_state < denoise_penalty_threshold

                
                # push the new value into the shift register and find the average
                new_register = shift_elements(registers[led_num], (r,g,b)) 
                smoothed_r, smoothed_g, smoothed_b = average_without_outliers(new_register,
                                                                              num_outliers,
                                                                              (former_r, former_g, former_b))

                # calculate the step in respect of the number of fade_levels
                step_r = (smoothed_r - former_r) / fade_levels
                step_g = (smoothed_g - former_g) / fade_levels
                step_b = (smoothed_b - former_b) / fade_levels

                new_r = step_r + former_r
                new_g = step_g + former_g
                new_b = step_b + former_b

                (new_dr, new_dg, new_db) = (new_r, new_g, new_b) if render_change else (dr,dg,db)
                denoise_machine[led_num] = (min(max_denoise_penalty, penalty_state), delta, (new_dr, new_dg, new_db))

                # do the hls conversion, desaturation and brightness adjustments

                h, l, s = colorsys.rgb_to_hls(new_dr/255, new_dg/255, new_db/255)
                (hue, lightness, saturation) =( int(round(h * 360)), int(round(l * 100)) , int(round(s * 100)))
                new_sat = int(((100.0-(saturation * 0.45))/100.0) * saturation)
                (dh, dl, ds) = (hue, int(lightness * self.brightness), new_sat)
                r, g, b = colorsys.hls_to_rgb(dh/360, dl/100, ds/100)
                d_r, d_g, d_b = (int(round(r * 255)) ,int(round(g * 255)), int(round(b * 255)))


                shifted_r, shifted_b, shifted_g = shift_color((d_r, d_g, d_b),
                                                              (self.r_shift, self.g_shift, self.b_shift))


                ws = 250 #white threshold
                output = Adafruit_WS2801.RGB_to_color(shifted_r if shifted_r < ws else ws,  
                                                      shifted_g if shifted_g < ws else ws,
                                                      shifted_b if shifted_b < ws else ws)

                ws2801.pixels.set_pixel(led_num, output)

                # finally set the former pixel and update the register
                former_pixels[led_num] = (new_r, new_g, new_b)
                registers[led_num] = new_register

            ws2801.pixels.show()
コード例 #24
0
import time
import RPi.GPIO as GPIO
from random import randint

# Import the WS2801 module.
import Adafruit_WS2801
import Adafruit_GPIO.SPI as SPI

# Configure the count of pixels:
PIXEL_COUNT = 50

# Alternatively specify a hardware SPI connection on /dev/spidev0.0:
SPI_PORT = 0
SPI_DEVICE = 0
pixels = Adafruit_WS2801.WS2801Pixels(PIXEL_COUNT,
                                      spi=SPI.SpiDev(SPI_PORT, SPI_DEVICE),
                                      gpio=GPIO)


class Pixel_Section:
    def __init__(self, leds, offset, length, step=1):
        max_pixels = leds.count()
        if offset > max_pixels:
            print("Eror: offset too far")
            offset = 0
        string_length = length * step
        if offset + string_length > max_pixels:
            print("Error : not enough pixels for that....")
            print("Going from {0:}  to {1:} exceeds max {2:}".format(
                offset, offset + string_length, max_pixels))
            string_length = max_pixels - offset
コード例 #25
0
def test_led(pixels):
    for i in range(pixels.count()):
        pixels.set_pixel(i, Adafruit_WS2801.RGB_to_color(255, 255, 255))
        pixels.show()
コード例 #26
0
def adacolor(rgb, g=False, b=False):
    if g and b:
        return Adafruit_WS2801.RGB_to_color(b, g, rgb)
    else:
        return Adafruit_WS2801.RGB_to_color(rgb[2], rgb[1], rgb[0])
コード例 #27
0
def change_color(pixels, r, g, b):
    print(r, g, b)
    pixels.set_pixels(Adafruit_WS2801.RGB_to_color(r, g, b))
    pixels.show()
コード例 #28
0
# Import the WS2801 module.
import Adafruit_WS2801
import Adafruit_GPIO.SPI as SPI
from random import randrange
import configparser
cfgpath = "/home/pi/HomeAutomation-python-Base/LED.cfg"
initcfg = configparser.ConfigParser()
initcfg.read(cfgpath)
# Configure the count of pixels:
PIXEL_COUNT = int(initcfg["LED"]["PixelCount"])

# Alternatively specify a hardware SPI connection on /dev/spidev0.0:
SPI_PORT = 0
SPI_DEVICE = 0
pixels = Adafruit_WS2801.WS2801Pixels(PIXEL_COUNT,
                                      spi=SPI.SpiDev(SPI_PORT, SPI_DEVICE),
                                      gpio=GPIO)
#defekte Pixel 0,1,43
defekt = [0, 1, 43]


# Define the wheel function to interpolate between different hues.
def wheel(pos):
    if pos < 85:
        return Adafruit_WS2801.RGB_to_color(pos * 3, 255 - pos * 3, 0)
    elif pos < 170:
        pos -= 85
        return Adafruit_WS2801.RGB_to_color(255 - pos * 3, 0, pos * 3)
    else:
        pos -= 170
        return Adafruit_WS2801.RGB_to_color(0, pos * 3, 255 - pos * 3)
コード例 #29
0
            pixels.clear()
            # first set all pixels at the begin
            for k in range(i):
                pixels.set_pixel(
                    k,
                    Adafruit_WS2801.RGB_to_color(color[0], color[1], color[2]))
            # set then the pixel at position j
            pixels.set_pixel(
                j, Adafruit_WS2801.RGB_to_color(color[0], color[1], color[2]))
            pixels.show()
            time.sleep(0.02)


if __name__ == "__main__":
    pixels = Adafruit_WS2801.WS2801Pixels(96,
                                          spi=SPI.SpiDev(SPI_PORT, SPI_DEVICE),
                                          gpio=GPIO)
    pixels.clear()
    pixels.show()

    blue = Adafruit_WS2801.RGB_to_color(0, 0, 255)
    white = Adafruit_WS2801.RGB_to_color(100, 100, 100)
    red = Adafruit_WS2801.RGB_to_color(255, 0, 0)
    green = Adafruit_WS2801.RGB_to_color(0, 255, 0)
    # for color in [red, green, white, blue]:
    #     for i in range(96):
    #         pixels.set_pixel(i, color)
    #         pixels.show()
    #         time.sleep(0.1)

    # while True:
コード例 #30
0
    for i in range(run_for):
        #print(i)
        r_window_a_do.next()
        r_window_b_do.next()
        r_window_c_do.next()
        r_window_d_do.next()
        l_window_a_do.next()
        l_window_b_do.next()
        l_window_c_do.next()
        l_window_d_do.next()
        pixels.show()
        time.sleep(.7)

    for trips in range(3):
        reverse = randint(0,1) == 1
        colour = Adafruit_WS2801.color_to_RGB(get_random_colour(360))
        run_for = whole_window.length
        whole_window_do = whole_window.appear_from_end(color=colour,
                                                       reverse=reverse)
        #snowman_1_do= snowman1.rainbow_cycle(steps=run_for, full_wheel=120,
        #                                     arc_span=10, laps=3)
        #snowman_2_do = snowman2.rainbow_cycle(steps=run_for, full_wheel=120,
        #                                     arc_span=10, laps=3, reverse=True)
        for i in range(whole_window.length-1):
            #print(i)
            whole_window_do.next()
            #snowman_1_do.next()
            #snowman_2_do.next()
            pixels.show()
            time.sleep(0.1)
コード例 #31
0
import Adafruit_WS2801 as af
import Adafruit_GPIO.SPI as SPI
import time
from datetime import datetime
import RPi.GPIO as GPIO

SPI_PORT = 0
SPI_DEVICE = 0

print("number of leds: ")
n = int(input())

leds = af.WS2801Pixels(n, spi=SPI.SpiDev(SPI_PORT, SPI_DEVICE), gpio=GPIO)

leds.clear()
leds.show()
time.sleep(1)
stamp = datetime.now()

for i in range(leds.count()):
    leds.clear()
    leds.set_pixel(i, af.RGB_to_color(255, 255, 255))
    leds.show()

total_time = (datetime.now() - stamp).total_seconds()
print("total time:", total_time)