Beispiel #1
0
def bleep():
    z = 1
    while z < 24:
        if (GPIO.input(12) == 0):

            print("Phone Button Pressed")
            time.sleep(1)
            restart()

        elif (GPIO.input(16) == 0):

            print("Handset Lifted")
            time.sleep(1)
            restart()
        else:

            GPIO.output(14, True)
            GPIO.output(26, True)
            unicorn.set_all(255, 0, 0)
            unicorn.show()
            time.sleep(0.2)
            GPIO.output(14, False)
            GPIO.output(26, False)
            unicorn.off()
            time.sleep(1)
            z += 1
            print(z)
    restart()
Beispiel #2
0
def pulse_color(
        color=(255, 255, 255), brightness=0.8, total_time=1, step_time=0.01):
    """
    Set all LCDs to green.
    :param color: tuple representing color as (R,G,B)
    :param brightness: max brightness value of pulse (0-1)
    :param total_time: time for full color pulse to complete, in seconds
    :param step_time: step time between brightness updates, in seconds
    """
    unicornhat.brightness(0)  # initial pulse value is 0
    unicornhat.set_all(color)
    unicornhat.show()
    # Calculate pulse data
    steps_half = int(total_time / step_time / 2)
    print('Half steps: {}'.format(steps_half))
    delta_brightness = brightness / steps_half
    # Start pulse up
    for _ in range(steps_half):
        brightness = unicornhat.get_brightness() + delta_brightness
        if brightness > 1:
            brightness = 1  # ensure max limit (in case of steps_half rounding)
        unicornhat.brightness(brightness)
        unicornhat.show()
        time.sleep(step_time)
    # Start pulse down
    for _ in range(steps_half):
        brightness = unicornhat.get_brightness() - delta_brightness
        if brightness < 0:
            brightness = 0  # ensure min limit (in case of steps_half rounding)
        unicornhat.brightness(brightness)
        unicornhat.show()
        time.sleep(step_time)
Beispiel #3
0
def set_color(value):
    # color RGB calues may be separated by comma, blank, semicolon, dash, colon in config
    colors = filter(None, re.split("[, ;\-:]", value))
    if len(colors) == 3:
        # RGB values
        for k, v in enumerate(colors):
            try:
                colors[k] = int(v)
            except ValueError:
                colors[k] = 0
            if colors[k] < 0:
                colors[k] = 0
            if colors[k] > 255:
                colors[k] = 255
        r, g, b = colors
    elif len(colors) == 1:
        # value in degrees Kelvin, only good between 1000..40000
        try:
            colors[0] = int(colors[0])
        except ValueError:
            colors[0] = 6504  # D65
        if colors[0] < 1000:
            colors[0] = 1000
        elif colors[0] > 40000:
            colors[0] = 40000
        r, g, b = ct.color_temperature_to_rgb(colors[0])

    config.set(my_section, 'color', ','.join([str(r), str(g), str(b)]))
    uh.set_all(r, g, b)
    uh.show()
    logger.info("Color set to " + config.get(my_section, 'color'))
Beispiel #4
0
def kscope(width, height, rgb):
    """ Freakin' Kaleidoscope F.X. """
    choices = [0, 1]
    choice = random.choice(choices)
    shift = lsc.getshift()
    mytime = lsd.getduration()
    xcoord, ycoord = lsd.getcoords(width, height)
    for _ in range(mytime):
        if width == height:
            for thisrot in range(0, 360, 90):
                unicornhat.rotation(thisrot)
                unicornhat.set_pixel(xcoord, ycoord, rgb[0], rgb[1], rgb[2])
            unicornhat.show()
        else:
            for thisrot in range(0, 270, 180):
                unicornhat.rotation(thisrot)
                unicornhat.set_pixel(xcoord, ycoord, rgb[0], rgb[1], rgb[2])
            unicornhat.show()
        if choice == 0:
            rgb = lsc.warpcolour(rgb)
        else:
            rgb = lsc.shiftcolour(rgb, shift)
        time.sleep(1)
        xcoord, ycoord = lsd.getcoords(width, height)
    unicornhat.set_all(0, 0, 0)
    unicornhat.show()
Beispiel #5
0
def hsv(addr, tags, stuff, source):
    h, s, v = stuff
    r, g, b = [int(c * 255) for c in colorsys.hsv_to_rgb(h, s, v)]
    print(r, g, b)
    unicorn.clear()
    unicorn.set_all(r, g, b)
    unicorn.show()
Beispiel #6
0
 def parpadear(self):
     for i in range(3):
         uh.set_all(200, 200, 200)
         uh.show()
         sleep(0.25)
         uh.clear()
         uh.show()
         sleep(0.5)
Beispiel #7
0
def cycle_colors():
    """ Cycle through all the colors one at a time. """

    colors = [C1, C2, C3, C4, C5, C6, C7, C8]

    for color in colors:
        unicornhat.set_all(color)
        unicornhat.show()
        sleep(1)
Beispiel #8
0
def end(*rgb):
    for i in range(3):
        hat.set_all(*rgb)
        hat.show()
        time.sleep(0.5)
        hat.clear()
        hat.show()
        time.sleep(0.5)
    exit()
def cycle_colors():
    """ Cycle through all the colors one at a time. """

    colors = [R, O, Y, W]

    for color in colors:
        unicornhat.set_all(color)
        unicornhat.show()
        sleep(1)
def reset_filter():
    for n in range(2):
        unicornhat.set_all(0, 0, 255)
        unicornhat.show()
        time.sleep(0.3)
        unicornhat.off()
        time.sleep(0.3)

    unicornhat.off()
    return True
Beispiel #11
0
    def _set_color(self, value=None):
        """ Set the brightness of the leds """

        if not value is None:
            self._color = value

        # convert to RGB ...
        (R, G, B) = self._hex_to_rgb(self._color)

        # ... and show
        unicornhat.set_all(R, G, B)
        unicornhat.show()
Beispiel #12
0
def blinker(blinks, color=[255, 0, 0], speed=0.02):
    uh.rotation(270)

    for b in range(blinks):
        r, g, b = color
        uh.set_all(r, g, b)
        uh.show()
        time.sleep(speed)

        uh.clear()
        uh.show()
        time.sleep(speed)
Beispiel #13
0
def set_colour(colour):
    r = '0x' + colour[0:2]
    g = '0x' + colour[2:4]
    b = '0x' + colour[4:6]

    r_value = int(r, 0)
    g_value = int(g, 0)
    b_value = int(b, 0)

    print('Updating color: r =', r_value, ', g =', g_value, ', b =', b_value)

    uh.set_all(r_value, g_value, b_value)
    uh.show()
Beispiel #14
0
def button_a(button, pressed):
    global current_index
    current_index = current_index + 1
    print(" Button press detected [{}][{}]".format(current_index,len(colors)))
    if current_index >= len(colors):
        #print(" end reached, reset to off")
        current_index = -1

    if current_index == -1:
        #print("  off")
        ore.off()
    else:
        #print("  selecting color for display")
        current_color = colors[current_index]
        ore.set_all(current_color)
        ore.show()
Beispiel #15
0
def eater(width, height, rgb):
    """ Eater """
    duration = getduration()
    rgb2 = lsc.getcolour()
    xcoord, ycoord = getcoords(width, height)
    unicornhat.set_all(rgb[0], rgb[1], rgb[2])
    unicornhat.show()
    for _ in range(duration):
        xcoord, ycoord = walk(width, height, rgb, xcoord, ycoord)
        unicornhat.set_pixel(xcoord, ycoord, 0, 0, 0)
        unicornhat.show()
        time.sleep(0.5)
        unicornhat.set_pixel(xcoord, ycoord, rgb2[0], rgb2[1], rgb2[2])
        unicornhat.show()
        time.sleep(0.5)
    unicornhat.set_all(0, 0, 0)
    unicornhat.show()
Beispiel #16
0
def fill(width, height, rgb):
    """ Fill """
    myrot = getrot(width, height)
    myrandom = random.randint(0, 1)
    mytime = getduration()
    unicornhat.rotation(myrot)
    for my_x in range(width):
        for my_y in range(height):
            unicornhat.set_pixel(my_x, my_y, rgb[0], rgb[1], rgb[2])
        unicornhat.show()
        if myrandom > 0:
            for myother_x in range(width):
                for myother_y in range(height):
                    unicornhat.set_pixel(myother_x, myother_y, 0, 0, 0)
        time.sleep(mytime / width)
    unicornhat.set_all(0, 0, 0)
    unicornhat.show()
Beispiel #17
0
def pulse(myred, mygreen, myblue):
    """ This function flashes the hat. """
    duration = getduration()
    choices = [0, 1, 2]
    colourfx = random.choice(choices)
    shift = lsc.getshift()
    for _ in range(0, duration):
        if colourfx > 0:
            if colourfx == 1:
                myred, mygreen, myblue = lsc.warpcolour((myred, mygreen, myblue))
            if colourfx == 2:
                myred, mygreen, myblue = lsc.shiftcolour((myred, mygreen, myblue), shift)
        unicornhat.set_all(myred, mygreen, myblue)
        unicornhat.show()
        time.sleep(0.5)
        unicornhat.set_all(0, 0, 0)
        unicornhat.show()
        time.sleep(0.5)
Beispiel #18
0
 def generateAnimation(self):
   # dropColumn
   # dropLength
   # for i in range(80):
   #   frame = Frame(self.height, self.width)
   #   frame.setAllPixels((63, 63, 126))
   row = 0
   for i in range(self.height * 8):
     frame = Frame(self.height, self.width)
     frame.setAllPixels((126,126,126))
     if row == self.height - 1:
       row = 0
     else:
       row += 1
     frame.setRow(row, [(63, 63, 126)] * self.width)
     print(frame.getGrid())
     if i == 20:
       uh.set_all((63, 63, 63))
     self.animation.append(frame)
   self.pauses = [10 / self.height * 8] * self.height
Beispiel #19
0
def set_color(value):
    # color RGB calues may be separated by comma, blank, semicolon, dash, colon in config
    colors = filter(None, re.split("[, ;\-:]", value))
    if len(colors) == 3:
        # RGB values
        for k, v in enumerate(colors):
            try:
                colors[k] = int(v)
            except ValueError:
                colors[k] = 0
            if colors[k] < 0:
                colors[k] = 0
            if colors[k] > 255:
                colors[k] = 255
        r, g, b = colors
    elif len(colors) == 1:
        # value in degrees Kelvin, only good between 1000..40000
        try:
            colors[0] = int(colors[0])
        except ValueError:
            colors[0] = 6504  # D65
        if colors[0] < 1000:
            colors[0] = 1000
        elif colors[0] > 40000:
            colors[0] = 40000
        r, g, b = ct.color_temperature_to_rgb(colors[0])
    else:
        # return early, no valid colors
        logger.info("Ignoring invalid color: " + value)
        return

    uh.set_all(r, g, b)
    uh.show()
    config.set(my_section, 'color', ','.join([str(r), str(g), str(b)]))
    status_topic = config.get(mqtt_section, 'base_topic') + config.get(
        my_section, 'client_topic') + 'status/color'
    mqttclient.publish(status_topic,
                       config.get(my_section, 'color'),
                       retain=True)
    logger.info("Color set to " + config.get(my_section, 'color'))
Beispiel #20
0
def blink(width, height, myred, mygreen, myblue):
    """ Blinks a pixel """
    duration = getduration()
    fxchoices = [0, 1, 2]
    colourfx = random.choice(fxchoices)
    choices = [0, 1]
    onoff = random.choice(choices)
    shift = lsc.getshift()
    for _ in range(0, duration):
        xcoord, ycoord = getcoords(width, height)
        unicornhat.set_pixel(xcoord, ycoord, myred, mygreen, myblue)
        unicornhat.show()
        time.sleep(0.5)
        if onoff < 1:
            unicornhat.set_pixel(xcoord, ycoord, 0, 0, 0)
        unicornhat.show()
        time.sleep(0.5)
        if colourfx > 0:
            if colourfx == 1:
                myred, mygreen, myblue = lsc.warpcolour((myred, mygreen, myblue))
            if colourfx == 2:
                myred, mygreen, myblue = lsc.shiftcolour((myred, mygreen, myblue), shift)
    unicornhat.set_all(0, 0, 0)
    unicornhat.show()
Beispiel #21
0
def restart():

    GPIO.output(14, True)
    GPIO.output(26, True)
    unicorn.set_all(0, 255, 0)
    unicorn.show()
    time.sleep(0.3)
    GPIO.output(14, False)
    GPIO.output(26, False)
    unicorn.off()
    time.sleep(0.2)
    GPIO.output(14, True)
    GPIO.output(26, True)
    unicorn.set_all(0, 255, 0)
    unicorn.show()
    time.sleep(0.3)
    GPIO.output(14, False)
    GPIO.output(26, False)
    unicorn.off()
    time.sleep(1)
    print("argv was", sys.argv)
    print("sys.executable was", sys.executable)
    print("restart now")
    os.execv(sys.executable, ['python'] + sys.argv)
unicorn.set_layout(unicorn.AUTO)
unicorn.rotation(0)
unicorn.brightness(0.5)
width, height = unicorn.get_shape()


def hex_to_rgb(col_hex):
    """Convert a hex colour to an RGB tuple."""
    col_hex = col_hex.lstrip('#')
    return bytearray.fromhex(col_hex)


while True:
    r = requests.get(
        'http://api.thingspeak.com/channels/1417/field/2/last.json', timeout=2)
    json = r.json()

    if 'field2' not in json:
        print('Error {status}: {error}'.format(status=json['status'],
                                               error=json['error']))
        time.sleep(5)
        continue

    r, g, b = hex_to_rgb(json['field2'])

    unicorn.set_all(r, g, b)

    unicorn.show()

    time.sleep(10)  # Be friendly to the API
Beispiel #23
0
    random.randint(3, 240),
    random.randint(3, 240),
]  # selects random start color in "safe zone"
#steps = [1, 3, 4]       # set wavelength
steps = [random.randint(1, 2),
         random.randint(1, 2),
         random.randint(1, 2)]  # selects random step beteween 1 and 5
print("INIT")  ## REPL


def getColor(index, colors, steps):
    if colors[index] >= 255 or colors[
            index] <= 0:  # flip the sign of the step at the max/min
        steps[index] *= -1
    colors[index] += steps[index]  # increment the value
    if colors[index] > 255:
        colors[index] = 255  # accounting for stepping over 255
    if colors[index] < 0: colors[index] = 0  # accounting for stepping under 0
    return (colors[index], colors, steps)  # returns colors for index


while True:
    r, colors, steps = getColor(0, colors, steps)  # gets red
    g, colors, steps = getColor(1, colors, steps)  # gets green
    b, colors, steps = getColor(2, colors, steps)  # gets blue
    print("STEP = ", steps, "COLOR = ", colors)  # REPL debug print
    uh.clear()
    uh.set_all(r, g, b)  # calls setPixel
    uh.show()
    time.sleep(random.random())  # random wait time between 0 and 1
def flash(t, red=255, green=255, blue=255):
    """ Set all pixel to specified color and wait for t seconds"""
    unicorn.set_all(red, green, blue)
    unicorn.show()
    time.sleep(t)
Beispiel #25
0
def rgb(addr, tags, stuff, source):
    r, g, b = stuff
    print(r, g, b)
    unicorn.clear()
    unicorn.set_all(r, g, b)
    unicorn.show()
Beispiel #26
0
    unicornhat.show()

def turn_on_red_light():
    print("RED")
    unicornhat.set_all(255,0,0)
    unicornhat.show()

# Get a reference to the Raspberry Pi camera.
# If this fails, make sure you have a camera connected to the RPi and that you
# enabled your camera in raspi-config and rebooted first.
camera = picamera.PiCamera()
camera.resolution = (320, 240)
output = np.empty((240, 320, 3), dtype=np.uint8)

# Load a sample picture and learn how to recognize it.
unicornhat.set_all(0, 0, 255)
unicornhat.show()

print("Loading known face image(s)")
allowed_image = face_recognition.load_image_file("allowed.jpg")
allowed_face_encoding = face_recognition.face_encodings(allowed_image)[0]

unicornhat.off()

# Initialize some variables
face_locations = []
face_encodings = []

while True:
    unicornhat.off()
Beispiel #27
0
 def setColor(self, red, green, blue):
     uh.set_all(red, green, blue)
     uh.show()
Beispiel #28
0
try:
    import psutil
except ImportError:
    exit("This script requires psutil.n\Install with: sudo pip install psutil")

# Set the brightness of the UnicornHAT - 1.0 is blindingly bright!
uh.brightness(0.5)

# Run in an infinite loop and display relevant colour on the UnicornHAT.
# Create your own 10 step gradient via http://www.perbang.dk/rgbgradient/
while True:
    cpu_raw = psutil.cpu_percent(interval=1)
    cpu = int(cpu_raw)
    #print cpu      # Uncomment out to show CPU usage in the terminal
    if cpu < 10:
        uh.set_all(0,255,0)         # Green
        uh.show()
    elif (cpu > 11) and (cpu < 20):
        uh.set_all(56,255,0)
        uh.show()
    elif (cpu > 21) and (cpu < 30): # Lime
        uh.set_all(113,255,0)
        uh.show()
    elif (cpu > 31) and (cpu < 40):
        uh.set_all(170,255,0)
        uh.show()
    elif (cpu > 41) and (cpu < 50): # Yellow
        uh.set_all(226,255,0)
        uh.show()
    elif (cpu > 51) and (cpu < 60):
        uh.set_all(255,226,0)
Beispiel #29
0
def turn_on_red_light():
    print("RED")
    unicornhat.set_all(255,0,0)
    unicornhat.show()
Beispiel #30
0
def turn_on_green_light():
    print("GREEN")
    unicornhat.set_all(0,255,0)
    unicornhat.show()