Last active
August 29, 2015 14:17
-
-
Save FluffyPira/a4e9570365c4b21c14cd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
##### | |
# | |
# PyGlow | |
# | |
##### | |
# | |
# Python module to control Pimoronis PiGlow | |
# [http://shop.pimoroni.com/products/piglow] | |
# | |
# * based on cpu percentage utilisation indicator by Jason (@Boeeerb) | |
# [https://github.com/Boeeerb/PiGlow] | |
# requires psutil | |
# - sudo apt-get install python-psutil | |
# - sudo yum install python-psutil | |
# | |
# * refactored and expanded by Elizabeth (@FluffyPira) | |
# | |
##### | |
from PyGlow import PyGlow | |
from time import sleep | |
import psutil | |
pyglow = PyGlow() | |
duration = 27.0 | |
delay = 0.2 | |
loop_iterations = int(duration / delay) | |
def individual_color(percentage, threshold, color, intensity = 20): | |
if percentage >= threshold: | |
pyglow.color(color, intensity) | |
else: | |
pyglow.color(color, 0) | |
def individual_led(percentage, threshold, number, intensity = 20): | |
if percentage >= threshold: | |
pyglow.led(number, intensity) | |
else: | |
pyglow.led(number, 0) | |
def cpu_percentage(): | |
return psutil.cpu_percent() | |
def mem_percentage(): | |
return psutil.virtual_memory().percent | |
def disk_percentage(): | |
return psutil.disk_usage('/').percent | |
def cpu_loop(): | |
return indicator_loop(cpu_percentage, 13) | |
def mem_loop(): | |
return indicator_loop(mem_percentage, 14) | |
def disk_loop(): | |
return indicator_loop(disk_percentage, 15) | |
def indicator_loop(fn, indicator_led): | |
for x in range(0, loop_iterations): | |
value = fn() | |
individual_led(value, 80, 1, 100) | |
individual_led(value, 60, 2, 80) | |
individual_led(value, 40, 3, 60) | |
individual_led(value, 20, 4, 40) | |
individual_led(value, 5, 5, 30) | |
individual_led(value, 0, 6, 20) | |
individual_led(value, 80, 7, 100) | |
individual_led(value, 60, 8, 80) | |
individual_led(value, 40, 9, 60) | |
individual_led(value, 20, 10, 40) | |
individual_led(value, 5, 11, 30) | |
individual_led(value, 0, 12, 20) | |
individual_led(value, 0, indicator_led, 100) | |
sleep(delay) | |
def animation_1(): | |
colors = ["red", "orange", "yellow", "green", "blue", "white"] | |
for color in colors: | |
pyglow.color(color, 100) | |
sleep(0.2) | |
sleep(0.6) | |
for color in reversed(colors): | |
pyglow.color(color, 0) | |
sleep(0.2) | |
def animation_2(): | |
for led in range(1, 19): | |
pyglow.led(led, 100) | |
sleep (0.075) | |
sleep(0.3) | |
for led in reversed(range(1, 19)): | |
pyglow.led(led, 0) | |
sleep (0.075) | |
def animation_3(): | |
for led in range(1, 7): | |
for arm in range(0, 3): | |
pyglow.led(led + (6 * arm), 100) | |
sleep (0.075) | |
sleep(0.3) | |
for led in reversed(range(1, 7)): | |
for arm in reversed(range(0, 3)): | |
pyglow.led(led + (6 * arm), 0) | |
sleep (0.075) | |
while True: | |
for fn in [animation_1, cpu_loop, animation_2, mem_loop, animation_3, disk_loop]: | |
pyglow.all(0) | |
sleep(0.25) | |
fn() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment