Пример #1
0
##
##  PyGlow
##
##      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: ")
Пример #2
0
##
##  PyGlow
##
##      python module to control Pimoronis PiGlow (http://shop.pimoroni.com/products/piglow)
##
##      * cpu.py - cpu percentage utilisation indicator by Jason (@Boeeerb https://github.com/Boeeerb/PiGlow)
##      ! requires psutil - sudo apt-get install python-psutil
##

from pyglow import PyGlow
from time import sleep
import psutil

pyglow = PyGlow()

while True:

    cpu = psutil.cpu_percent()
    pyglow.all(0)

    if cpu < 5:
        pyglow.color("white", 20)
    elif cpu < 20:
        pyglow.color("white", 20)
        pyglow.color("blue", 20)
    elif cpu < 40:
        pyglow.color("white", 20)
        pyglow.color("blue", 20)
        pyglow.color("green", 20)
    elif cpu < 60:
        pyglow.color("white", 20)
Пример #3
0
## Xmas Lights by Dan Pullan (https://danielpullan.co.uk)
## Does some christmas-themed patterns on a Piglow, which can be bought from Pimoroni.
## Thanks to @boeeerb who wrote the PyGlow Python Module.
## Originally created for Python2 on 10/04/2014, rewritten for Python3 on 20/11/2018

from pyglow import PyGlow
import sys

pyglow = PyGlow()

val = input("How bright? (0-225): ")

if val < 0 or val > 255:
	print("Sorry, try again")
	sys.exit()

speedval = input("How fast? (500 recommended): ")


pyglow.all(0)

print("Check out my bright idea.")
pyglow.pulse(1, val, speedval)
pyglow.pulse(2, val, speedval)
pyglow.pulse(3, val, speedval)
pyglow.pulse(4, val, speedval)
pyglow.pulse(5, val, speedval)
pyglow.pulse(6, val, speedval)
pyglow.pulse(7, val, speedval)
pyglow.pulse(8, val, speedval)
pyglow.pulse(9, val, speedval)
Пример #4
0
#! /usr/bin/python
#
print "Content-Type: text/html\n"

from pyglow import PyGlow
from time import sleep

pyglow = PyGlow()
pyglow.all(0)

max_brightness = 255 #(0 == off, 75 == bright, 255 == blinding!)
single_led = 2 #1-18

for x in range (0, max_brightness):
	pyglow.led(single_led, x)
	sleep(0.001)

for x in range (max_brightness, 0, -1):
	pyglow.led(single_led, x)
	sleep(0.001)

pyglow.all(0)
Пример #5
0
##
##  PyGlow
##
##      python module to control Pimoronis PiGlow (http://shop.pimoroni.com/products/piglow)
##
##      * pulsetest.py - test the pulsing light feature
##

from pyglow import PyGlow

pyglow = PyGlow()

val = input("Maximum Brightness: ")
speedval = input("Speed (Try 500 as a default): ")
pyglow.all(0)
print("Pulsing 1 Light")
pyglow.pulse(1, val, speedval)
print("Pulsing Arms")
pyglow.pulse_arm(1, val, speedval)
pyglow.pulse_arm(2, val, speedval)
pyglow.pulse_arm(3, val, speedval)
print("Pulsing All")
pyglow.pulse_all(val, speedval)
Пример #6
0
##
##  PyGlow
##
##      python module to control Pimoronis PyGlow (http://shop.pimoroni.com/products/pyglow)
##
##      * set_leds.py - how to control a individual set of leds by Ben (@ben_leb)
##

from pyglow import PyGlow
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
Пример #7
0
#altered sample code from Pimoroni

from pyglow import PyGlow
from time import sleep

pyglow = PyGlow()

#set all the LEDs to off:
pyglow.all(0)

#turn on LEDs then off again
pyglow.led(1,100)
sleep(1)
pyglow.led(1,0)
sleep(1)

#light up the LEDs
pyglow.update_leds()


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

pyglow.led(3,100)
sleep(1)
pyglow.led(3,0)
sleep(1)
pyglow.update_leds()
Пример #8
0
 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()
Пример #9
0
#!/usr/bin/env python

from pyglow import PyGlow

pg = PyGlow()

pg.all(0) 
Пример #10
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()
Пример #11
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)
Пример #12
0
#! /usr/bin/python
#
print "Content-Type: text/html\n"

from pyglow import PyGlow
from time import sleep

pyglow = PyGlow()
pyglow.all(0)

max_brightness = 255 #(0 == off, 75 == bright, 255 == blinding!)

#Pulse all LEDs up to max_brightness and back to off
for x in range (0, max_brightness):
	pyglow.all(x)
	sleep(0.001)

for x in range (max_brightness, 0, -1):
	pyglow.all(x)
	sleep(0.001)

pyglow.all(0)
Пример #13
0
import sys
from pyglow import PyGlow

pyglow = PyGlow()

arm1 = int(sys.argv[1])
arm2 = int(sys.argv[2])
arm3 = int(sys.argv[3])
brightness = int(sys.argv[4])

entire_led_array = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18]
sub_led_array = []

pyglow.set_leds(entire_led_array,0)

for x in range(0, arm1):
	sub_led_array.append(x+1)
for y in range(6, 6 + arm2):
	sub_led_array.append(y+1)
for z in range(12, 12 + arm3):
	sub_led_array.append(z+1)

#print str(sub_led_array)
pyglow.set_leds(sub_led_array,brightness)

pyglow.update_leds()
#!/usr/bin/env python

import sys
import time
import requests
import subprocess
import re

# get PyGlow from https://github.com/benleb/PyGlow
sys.path.append('vendor/PyGlow')

from pyglow import PyGlow

pyglow = PyGlow()
pyglow.all(0)

def throbcolorout(maxcolor, intensity, delay):
  i = 1
  while i <= maxcolor:
    pyglow.color(i, intensity)
    time.sleep(delay)
    i += 1
  time.sleep(delay)

def throbcolorin(maxcolor, intensity, delay):
  i = maxcolor
  while i >= 1:
    pyglow.color(i, intensity)
    time.sleep(delay)
    i -= 1
  time.sleep(delay)
Пример #15
0
##
##  PyGlow
##
##      python module to control Pimoronis PyGlow (http://shop.pimoroni.com/products/pyglow)
##
##      * clock.py - binary clock by Jason (@Boeeerb https://github.com/Boeeerb/PyGlow)
##      ! requires psutil - sudo apt-get install python-psutil
##


from pyglow import PyGlow
from time import sleep
import psutil

pyglow = PyGlow()

while True:

    cpu = psutil.cpu_percent()
    pyglow.all(0)

    if cpu < 5:
        pyglow.color("white", 20)
    elif cpu < 20:
        pyglow.color("white", 20)
        pyglow.color("blue", 20)
    elif cpu < 40:
        pyglow.color("white", 20)
        pyglow.color("blue", 20)
        pyglow.color("green", 20)
    elif cpu < 60:
Пример #16
0
import psutil
from pyglow import PyGlow
import signal
import sys

pyglow = PyGlow()
# Set the order in which you want the lights to come one
# In this case they start in the center and spiral outwards
led_list = [6, 12, 18, 5, 11, 17, 4, 10, 16, 3, 9, 15, 2, 8, 14, 1, 7, 13]


def signal_handler(signal, frame):
        pyglow.all(0)
        pyglow.update_leds()
        sys.exit(0)

signal.signal(signal.SIGINT, signal_handler)
# Set some variables
brightness = 100
previous_value = 0
number_leds = 18

while True:
	cpu_percent = psutil.cpu_percent(interval=11)
	number_to_display = (cpu_percent / (100/number_leds))
	cpu_rounded = int(number_to_display)
	print cpu_percent
	if (cpu_rounded > 18):
		cpu_rounded = 18
	# alter brightness based on load
	if (previous_value == cpu_rounded):
Пример #17
0
##
##  PyGlow
##
##      python module to control Pimoronis PiGlow (http://shop.pimoroni.com/products/piglow)
##
##      * clock.py - binary clock by Jason (@Boeeerb https://github.com/Boeeerb/PiGlow)
##


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

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
Пример #18
0
##
##  PyGlow
##
##      python module to control Pimoronis PiGlow (http://shop.pimoroni.com/products/piglow)
##
##      * pulsetest.py - test the pulsing light feature
##

from pyglow import PyGlow

pyglow = PyGlow()

val = input("Maximum Brightness: ")
speedval = input("Speed (Try 500 as a default): ")
pyglow.all(0)
print("Pulsing 1 Light")
pyglow.pulse(1, val, speedval)
print("Pulsing Arms")
pyglow.pulse_arm(1, val, speedval)
pyglow.pulse_arm(2, val, speedval)
pyglow.pulse_arm(3, val, speedval)
print("Pulsing All")
pyglow.pulse_all(val, speedval)
Пример #19
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()
Пример #20
0
#!/usr/bin/env python

import sys
import time
import requests
import subprocess
import re

# get PyGlow from https://github.com/benleb/PyGlow
sys.path.append('vendor/PyGlow')

from pyglow import PyGlow

pyglow = PyGlow()
pyglow.all(0)


def throbcolorout(maxcolor, intensity, delay):
    i = 1
    while i <= maxcolor:
        pyglow.color(i, intensity)
        time.sleep(delay)
        i += 1
    time.sleep(delay)


def throbcolorin(maxcolor, intensity, delay):
    i = maxcolor
    while i >= 1:
        pyglow.color(i, intensity)
        time.sleep(delay)