Beispiel #1
0
def wave(led_max=150, frame_delay=0.02, frame_count=None, initial_brightness=None, direction=None):
    """
    Creates a wave effect through the PiGlow board.

    Args (all are optional):
        led_max (int): the LED brightness at the peak of the wave.
        frame_delay (float): the time between each transition.
        frame_count (int): the number of transitions in a single wave.
        initial_brightness (int): the current brightness of the LEDs.
        direction (string): either 'inward' or 'outward'.
    """
    if initial_brightness is None:
        initial_brightness = min(piglow.get())

    if direction is None:
        direction = 'outward'

    if frame_count is None:
        frame_count = len(LEDS)

    if direction == 'outward':
        LEDS.reverse()

    led_set_count = len(LEDS)

    # initialise all of the LEDs
    piglow.all(initial_brightness)
    piglow.show()

    wave = _create_led_sine_wave(led_max, frame_count, initial_brightness, led_set_count)

    for wave_point in _window(wave, led_set_count):
        for i, led_set in enumerate(LEDS):
            for led in led_set:
                piglow.led(led, int(wave_point[i]))

            piglow.show()
            sleep(frame_delay)
Beispiel #2
0
def main():
    piglow.clear_on_exit = False
    piglow.auto_update = True
    piglow.all(0)

    try:
        status = update()
    except:     # Unknown error raised when the wifi adapter dies
        piglow.blue(1)
        # os.system('sudo shutdown -r now')

    met_status = status.pop('metropolitan')
    jubilee_status = status.pop('jubilee')

    if datetime.date.today().isoweekday() in (6, 7):
        # No Waterloo and City service on the weekend
        status.pop('waterloo-city')

    # Reminder: sets can't be keys to dicts but frozensets can
    other_statuses = frozenset(status.values())
    other_status = {frozenset(['GOOD']): 'GOOD',
                    frozenset(['GOOD', 'OK']): 'OK'}.get(other_statuses, 'BAD')

    met_leds = {'GOOD': [1],
                'OK':   [1, 2],
                'BAD':  [1, 2, 3, 4, 5, 6]}[met_status]

    jubilee_leds = {'GOOD': [7],
                    'OK':   [7, 8],
                    'BAD':  [7, 8, 9, 10, 11, 12]}[jubilee_status]

    other_leds = {'GOOD': [13],
                  'OK':   [13, 14],
                  'BAD':  [13, 14, 15, 16, 17, 18]}[other_status]

    [piglow.led(n, 1) for n in met_leds + jubilee_leds + other_leds]
Beispiel #3
0
def swirly():
#LEDs On:
    piglow.led(1,br)
    sleep(slp)
    piglow.led(7,br)
    sleep(slp)
    piglow.led(18,br)
    sleep(slp)

    piglow.led(2,br)
    sleep(slp)
    piglow.led(8,br)
    sleep(slp)
    piglow.led(17,br)
    sleep(slp)

    piglow.led(3,br)
    sleep(slp)
    piglow.led(9,br)
    sleep(slp)
    piglow.led(16,br)
    sleep(slp)

    piglow.led(4,br)
    sleep(slp)
    piglow.led(14,br)
    sleep(slp)
    piglow.led(6,br)
    sleep(slp)

    piglow.led(5,br)
    sleep(slp)
    piglow.led(15,br)
    sleep(slp)
    piglow.led(12,br)
    sleep(slp)

    piglow.led(10,br)
    sleep(slp)
    piglow.led(11,br)
    sleep(slp)
    piglow.led(13,br)
    sleep(slp)

#LEDs Off:
    piglow.led(1,0)
    sleep(slp)
    piglow.led(7,0)
    sleep(slp)
    piglow.led(18,0)
    sleep(slp)

    piglow.led(2,0)
    sleep(slp)
    piglow.led(8,0)
    sleep(slp)
    piglow.led(17,0)
    sleep(slp)

    piglow.led(3,0)
    sleep(slp)
    piglow.led(9,0)
    sleep(slp)
    piglow.led(16,0)
    sleep(slp)

    piglow.led(4,0)
    sleep(slp)
    piglow.led(14,0)
    sleep(slp)
    piglow.led(6,0)
    sleep(slp)

    piglow.led(5,0)
    sleep(slp)
    piglow.led(15,0)
    sleep(slp)
    piglow.led(12,0)
    sleep(slp)

    piglow.led(10,0)
    sleep(slp)
    piglow.led(11,0)
    sleep(slp)
    piglow.led(13,0)
    sleep(slp)
Beispiel #4
0
def swirly():
#LEDs On:
    piglow.led(1,25)
    sleep(slp)
    piglow.led(7,25)
    sleep(slp)
    piglow.led(18,25)
    sleep(slp)

    piglow.led(2,25)
    sleep(slp)
    piglow.led(8,25)
    sleep(slp)
    piglow.led(17,25)
    sleep(slp)

    piglow.led(3,25)
    sleep(slp)
    piglow.led(9,25)
    sleep(slp)
    piglow.led(16,25)
    sleep(slp)

    piglow.led(4,25)
    sleep(slp)
    piglow.led(14,25)
    sleep(slp)
    piglow.led(6,25)
    sleep(slp)

    piglow.led(5,25)
    sleep(slp)
    piglow.led(15,25)
    sleep(slp)
    piglow.led(12,25)
    sleep(slp)

    piglow.led(10,25)
    sleep(slp)
    piglow.led(11,25)
    sleep(slp)
    piglow.led(13,25)
    sleep(slp)

#LEDs Off:
    piglow.led(1,0)
    sleep(slp)
    piglow.led(7,0)
    sleep(slp)
    piglow.led(18,0)
    sleep(slp)

    piglow.led(2,0)
    sleep(slp)
    piglow.led(8,0)
    sleep(slp)
    piglow.led(17,0)
    sleep(slp)

    piglow.led(3,0)
    sleep(slp)
    piglow.led(9,0)
    sleep(slp)
    piglow.led(16,0)
    sleep(slp)

    piglow.led(4,0)
    sleep(slp)
    piglow.led(14,0)
    sleep(slp)
    piglow.led(6,0)
    sleep(slp)

    piglow.led(5,0)
    sleep(slp)
    piglow.led(15,0)
    sleep(slp)
    piglow.led(12,0)
    sleep(slp)

    piglow.led(10,0)
    sleep(slp)
    piglow.led(11,0)
    sleep(slp)
    piglow.led(13,0)
    sleep(slp)
Beispiel #5
0
    binsec = "%06d" % int(bin(sec)[2:])

    # Check if current hour is different and set ready to flash hour
    if hourcurrent != hour:
        hourcount = hour
        hourcurrent = hour

    
    if armbottom == "h":
	arm3 = list(binhour)
    elif armbottom == "m":
        arm3 = list(binmin)
    else:
        arm3 = list(binsec)
    led13 = ledbrightness if arm3[5] == "1" else 0
    piglow.led(13,led13)
    led14 = ledbrightness if arm3[4] == "1" else 0
    piglow.led(14,led14)
    led15 = ledbrightness if arm3[3] == "1" else 0
    piglow.led(15,led15)
    led16 = ledbrightness if arm3[2] == "1" else 0
    piglow.led(16,led16)
    led17 = ledbrightness if arm3[1] == "1" else 0
    piglow.led(17,led17)
    led18 = ledbrightness if arm3[0] == "1" else 0
    piglow.led(18,led18)

    if armright == "h":
	arm2 = list(binhour)
    elif armright == "m":
        arm2 = list(binmin)
Beispiel #6
0
            hour = hour - 12

    # Check if current hour is different and set ready to flash hour
    if hourcurrent != hour:
        hourcount = hour
        hourcurrent = hour

    if armbottom == "h":
        arm3 = hour
    elif armbottom == "m":
        arm3 = min
    else:
        arm3 = sec

    for x in range(6):
        piglow.led(13 + x, (arm3 & (1 << x)) * ledbrightness)

    if armright == "h":
        arm2 = hour
    elif armright == "m":
        arm2 = min
    else:
        arm2 = sec

    for x in range(6):
        piglow.led(7 + x, (arm2 & (1 << x)) * ledbrightness)

    if armtop == "h":
        arm1 = hour
    elif armtop == "m":
        arm1 = min
Beispiel #7
0
import piglow
import time

for x in range(18):
    piglow.led(x+1, 100)
    piglow.show()
    time.sleep(0.5)
    piglow.led(x+1, 0)
    piglow.show()
    time.sleep(0.5)
Beispiel #8
0
            hour = hour - 12

    # Check if current hour is different and set ready to flash hour
    if hourcurrent != hour:
        hourcount = hour
        hourcurrent = hour

    if armbottom == "h":
        arm3 = hour
    elif armbottom == "m":
        arm3 = min
    else:
        arm3 = sec

    for x in range(6):
        piglow.led(13 + x, (arm3 & (1 << x)) * ledbrightness)

    if armright == "h":
        arm2 = hour
    elif armright == "m":
        arm2 = min
    else:
        arm2 = sec

    for x in range(6):
        piglow.led(7 + x, (arm2 & (1 << x)) * ledbrightness)

    if armtop == "h":
        arm1 = hour
    elif armtop == "m":
        arm1 = min
Beispiel #9
0
## Example by tng - @TommyBobbins               ##
##################################################

import piglow

piglow.auto_update = True

from time import sleep
import random

# Maximum random sleep between switching an LED on or off
sleep_period = 0.001

# Switch off all the lights first
piglow.all(0)

# We only want to select the Red, Orange and Yellow LEDs (roy)
roy_leds = [ "01","02","03", "07", "08", "09", "13","14", "15" ]

def random_brightness():
    sleep(random.uniform(0,sleep_period))
    return random.randint(0,255)

while True:
    # Switch one random roy LED to one random brightness
    led_to_switch = int(random.choice(roy_leds))
    piglow.led(led_to_switch, random_brightness())
    # Switch one random roy LED off 
    led_to_switch = int(random.choice(roy_leds))
    piglow.led(led_to_switch, 0)
Beispiel #10
0
#!/usr/bin/env python
##################################################
## Switch each colour on in sequence on and off ##
##                                              ##
## Example by Jason - @Boeeerb                  ##
##################################################

import piglow
from time import sleep

piglow.auto_update = True

val = 20
colour = 1

while True:
    if colour == 19:
        colour = 1
        if val == 20:
            val = 0
        else:
            val = 20

    piglow.led(colour, val)
    sleep(0.2)

    colour += 1
C_1 = 13
C_2 = 14
C_3 = 15
C_4 = 16
C_5 = 5
C_6 = 4
C_7 = 1
C_8 = 2

amp = MAX9744()
amp.set_volume(0)

while True:
    conn = sqlite3.connect('db/settings.db')
    curs = conn.cursor()
    curs.execute(
        "SELECT value FROM af_overrides where paramName='backlightBrightness'")
    setting = curs.fetchone()
    z = setting[0]
    conn.close()
    piglow.led(C_1, z)
    piglow.led(C_2, z)
    piglow.led(C_3, z)
    piglow.led(C_4, z)
    piglow.led(C_5, z)
    piglow.led(C_6, z)
    piglow.led(C_7, z)
    piglow.led(C_8, z)
    piglow.show()
    time.sleep(0.3)
Beispiel #12
0
import piglow
import time

for x in range(18):
    piglow.led(x + 1, 100)
    piglow.show()
    time.sleep(0.5)
    piglow.led(x + 1, 0)
    piglow.show()
    time.sleep(0.5)
Beispiel #13
0
import random
from time import sleep

import piglow


piglow.auto_update = True

# Maximum random sleep between switching an LED on or off
sleep_period = 0.001

# Switch off all the lights first
piglow.all(0)

# We only want to select the Red, Orange and Yellow LEDs (roy)
roy_leds = ["01", "02", "03", "07", "08", "09", "13", "14", "15"]


def random_brightness():
    sleep(random.uniform(0, sleep_period))
    return random.randint(0, 255)


while True:
    # Switch one random roy LED to one random brightness
    led_to_switch = int(random.choice(roy_leds))
    piglow.led(led_to_switch, random_brightness())
    # Switch one random roy LED off 
    led_to_switch = int(random.choice(roy_leds))
    piglow.led(led_to_switch, 0)