Пример #1
0
from time import sleep

pyglow = PyGlow()

try:

    while True:

        ## choose a set of leds
        leds = [1,3,5,11,13,15]
        ## save them with the brightness you want
        pyglow.set_leds(leds,50)
        ## wait to demonstrate...
        sleep(3)
        ## light up the leds!
        pyglow.update_leds()

        sleep(3)

        ## now we want to shut down the first set
        pyglow.set_leds(leds,0)
        ## ...build a newer, brighter set
        leds = [2,4,9]
        pyglow.set_leds(leds,150)
        ## and update the leds!
        pyglow.update_leds()

except KeyboardInterrupt:

    pyglow.all(0)
Пример #2
0
#! /usr/bin/python
#
print "Content-Type: text/html\n"

from pyglow import PyGlow
from time import sleep
from datetime import datetime
import random

pyglow = PyGlow()
pyglow.all(0)

random.seed(datetime.now().time())

randomLightsInt = random.randint(0,262143)

randomLightBits = "{0:b}".format(randomLightsInt)

i = 1
leds = []
for c in randomLightBits:
	if (int(c)*i>0):
		leds.append(i)
	i=i+1

pyglow.set_leds(leds, 50)
pyglow.update_leds()
Пример #3
0
pyglow = PyGlow()


### You can customise these settings ###

show12hr = 0            # Show 12 or 24hr clock - 0= 24hr, 1= 12hr
ledbrightness = 50      # Set brightness of LED - 1-255 (recommend 10-20, put 0 and you won't see it!)
hourflash = 1           # Choose how to flash change of hour - 1= white leds, 2= all flash

armtop = "s"            # h= hour, m= minutes, s= seconds
armright = "m"
armbottom = "h"

### End of customising ###

pyglow.all(0)

hourcount = 0
hourcurrent = 0

while True:
    time = datetime.now().time()
    hour,min,sec = str(time).split(":")
    sec,micro = str(sec).split(".")
    
    hour = int(hour)
    if show12hr == 1:
        if hour > 12:
            hour = hour - 12

    min = int(min)
Пример #4
0
##
##      python module to control Pimoronis PiGlow (http://shop.pimoroni.com/products/piglow)
##
##      * test.py - set brightness for each color individually
##

from pyglow import PyGlow

pyglow = PyGlow()

val = input("White: ")
pyglow.color("white", val)

val = input("Blue: ")
pyglow.color("blue", val)

val = input("Green: ")
pyglow.color("green", val)

val = input("Yellow: ")
pyglow.color("yellow", val)

val = input("Orange: ")
pyglow.color("orange", val)

val = input("Red: ")
pyglow.color("red", val)

val = input("All: ")
pyglow.all(val)
Пример #5
0
#!/usr/bin/env python

from pyglow import PyGlow

pg = PyGlow()

pg.all(0) 
Пример #6
0
class PyGlowCPU(object):

    """Main PyGlowCPU app."""

    def __init__(self, method=1):
        """Setup daemon stuff."""
        self.stdin_path = '/dev/null'
        self.stdout_path = '/dev/tty'
        self.stderr_path = '/dev/tty'
        self.pidfile_path = '/var/run/pyglowcpu.pid'
        self.pidfile_timeout = 5
        self.method = method

    def run(self):
        """Entry point for DaemonRunner.do_action()."""
        self.piglow = PyGlow()
        atexit.register(lambda: self.piglow.all(0))
        mth = getattr(self, 'method%d' % (self.method))
        mth()

    def method1(self):
        """CPU load increases ring usage every 20%."""
        while True:
            cpu = psutil.cpu_percent()
            self.piglow.all(0)
            if 0 < cpu < 10:
                pass
            elif 10 < cpu < 20:
                self.piglow.red(20)
            elif cpu < 20:
                self.piglow.red(20)
                self.piglow.orange(20)
            elif cpu < 40:
                self.piglow.red(20)
                self.piglow.orange(20)
                self.piglow.yellow(20)
            elif cpu < 60:
                self.piglow.red(20)
                self.piglow.orange(20)
                self.piglow.yellow(20)
                self.piglow.green(20)
            elif cpu < 80:
                self.piglow.red(50)
                self.piglow.orange(50)
                self.piglow.yellow(50)
                self.piglow.green(50)
                self.piglow.blue(50)
            else:
                self.piglow.all(100)
            sleep(0.2)

    def method2(self):
        """Represent 20% on arm1."""
        while True:
            cpu = psutil.cpu_percent()
            self.piglow.all(0)

            if 0 < cpu < 10:
                pass
            elif 10 < cpu < 20:
                self.piglow.led1(20)
            elif cpu < 20:
                self.piglow.led1(20)
                self.piglow.led2(20)
            elif cpu < 40:
                self.piglow.led1(20)
                self.piglow.led2(20)
                self.piglow.led3(20)
            elif cpu < 60:
                self.piglow.led1(30)
                self.piglow.led2(30)
                self.piglow.led3(30)
                self.piglow.led4(30)
            elif cpu < 80:
                self.piglow.led1(60)
                self.piglow.led2(60)
                self.piglow.led3(60)
                self.piglow.led4(60)
                self.piglow.led5(60)
            else:
                self.piglow.arm1(100)
            sleep(0.2)

    def method3(self):
        """Represent 20% on arm2."""
        while True:
            cpu = psutil.cpu_percent()
            self.piglow.all(0)

            if 0 < cpu < 10:
                pass
            elif 10 < cpu < 20:
                self.piglow.led7(20)
            elif cpu < 20:
                self.piglow.led7(20)
                self.piglow.led8(20)
            elif cpu < 40:
                self.piglow.led7(20)
                self.piglow.led8(20)
                self.piglow.led9(20)
            elif cpu < 60:
                self.piglow.led7(30)
                self.piglow.led8(30)
                self.piglow.led9(30)
                self.piglow.led10(30)
            elif cpu < 80:
                self.piglow.led7(60)
                self.piglow.led8(60)
                self.piglow.led9(60)
                self.piglow.led10(60)
                self.piglow.led11(60)
            else:
                self.piglow.arm2(100)
            sleep(0.2)

    def method4(self):
        """Represent 20% on arm3."""
        while True:
            cpu = psutil.cpu_percent()
            self.piglow.all(0)

            if 0 < cpu < 10:
                pass
            elif 10 < cpu < 20:
                self.piglow.led13(20)
            elif cpu < 20:
                self.piglow.led13(20)
                self.piglow.led14(20)
            elif cpu < 40:
                self.piglow.led13(20)
                self.piglow.led14(20)
                self.piglow.led15(20)
            elif cpu < 60:
                self.piglow.led13(30)
                self.piglow.led14(30)
                self.piglow.led15(30)
                self.piglow.led16(30)
            elif cpu < 80:
                self.piglow.led13(60)
                self.piglow.led14(60)
                self.piglow.led15(60)
                self.piglow.led16(60)
                self.piglow.led17(60)
            else:
                self.piglow.arm3(100)
            sleep(0.2)

    def method5(self):
        """Represent using gamma."""
        while True:
            cpu = psutil.cpu_percent()
            self.piglow.all(int(cpu*2))
            sleep(0.2)

    def method6(self):
        """Rotate the arms CW."""
        armiter = cycle((1,2,3))
        for target_arm in armiter:
            cpu = psutil.cpu_percent()
            self.piglow.all(0)

            target_arm -= 1  # 0-based indexing
            a = np.array([0,1,2,3,4,5])
            p = np.floor(np.percentile(a, cpu))
            for x in range(int(p)+1):
                f = getattr(self.piglow, 'led%d' % self.piglow.arm_led_list[target_arm][x])
                f(20)

            sleep(0.2)

    def method7(self):
        """Rotate the arms CCW."""
        armiter = cycle((3,2,1))
        for target_arm in armiter:
            cpu = psutil.cpu_percent()
            self.piglow.all(0)

            target_arm -= 1  # 0-based indexing
            a = np.array([0,1,2,3,4,5])
            p = np.floor(np.percentile(a, cpu))
            for x in range(int(p)+1):
                f = getattr(self.piglow, 'led%d' % self.piglow.arm_led_list[target_arm][x])
                f(20)

            sleep(0.2)
Пример #7
0
from pyglow import PyGlow # imports PyGlow module
from time import sleep

pyglow = PyGlow() # defines pyglow as the function PyGlow
pyglow.all(0) # sets all lights off

pyglow.led(1, 100)
sleep(1)
pyglow.led(1, 0)
sleep(1)

pyglow.update_leds()