def leg_bar_intensity(leg_index, percentage, intensity=1.0): """Display a bargraph on a leg. A leg/arm/spoke is the line of 6 LEDs the emanates from the center of Piglow to the edge. :param leg_index: leg from 0 to 2 :param percentage: percentage to display in decimal :param intensity: percentage of maximum intensity """ # From inner led to outer led legs = [[5, 4, 3, 2, 1, 0], [11, 10, 9, 8, 7, 6], [17, 16, 15, 14, 13, 12]] if percentage > 1.0 or percentage < 0: raise ValueError("percentage must be between 0.0 and 1.0") if intensity > 1.0 or intensity < 0: raise ValueError("intensity must be between 0.0 and 1.0") # 1530 = 6 * 255 amount = int(1530.0 * percentage * intensity) for led_index in legs[leg_index % 3]: piglow.set( led_index, int(255 * intensity) if amount > 255 * intensity else int(amount * intensity)) amount = 0 if amount < (255 * intensity) else amount - (255 * intensity)
def _cycle(leds, speed, low, high): """ Cycle each LED from low to high in order """ pulse_range = range(low, high) wait_for = 1/speed # Set each LED to the LOW state _set(leds, low) for i in range(0, len(leds)): for c in pulse_range: # Increase the LED to HIGH piglow.set(leds[i], c) piglow.show() sleep(wait_for) # Decrease the previous LED back to LOW at same rate if i > 0: piglow.set(leds[i-1], high-(c-low)) piglow.show() sleep(wait_for) # Decrease the final LED back to LOW state _dim(leds[-1], speed, high, low) # Set each LED to the LOW state _set(leds, low)
def _dim(led, speed, high, low): """ Dims the led from high to low at the given speed """ dim_range = range(low, high) wait_for = 1/speed for c in reversed(dim_range): piglow.set(led, c) piglow.show() sleep(wait_for)
def _pulse(led, speed, low, high): """ Pulse the LED from low to high """ pulse_range = range(low, high) wait_for = 1/speed for c in pulse_range: piglow.set(led, c) piglow.show() sleep(wait_for) for c in reversed(pulse_range): piglow.set(led, c) piglow.show() sleep(wait_for)
def _set(leds, value): """ Sets the value of each led """ for led in leds: piglow.set(led, value) piglow.show()
def _clear_all(): """ Clear all LEDs """ for l in range(0, 18): piglow.set(l, 0) piglow.show()
#!/usr/bin/env python import piglow from time import sleep piglow.auto_update = True BRIGHT_MAX = 20 bright = BRIGHT_MAX for count in range(4): for x in reversed(range(6)): arr = [x, x + 6, x + 12] piglow.set(arr, bright) sleep(0.1) bright = 0 if bright == BRIGHT_MAX else BRIGHT_MAX
import piglow import time piglow.auto_update = True print("Testing continuous set...") piglow.set(0, [100,100,100]) time.sleep(1) piglow.all(0) print("Testing list/list set...") piglow.set([0,2,4,6,8,10,12,14,16],[100,100,100,100,100,100,100,100,100]) time.sleep(1) piglow.all(0) print("Testing single value, multi LED set...") piglow.set([1,3,5,7,9,11,13,15,17],100) time.sleep(1) piglow.all(0)
#!/usr/bin/env python import piglow from time import sleep piglow.auto_update = True for count in range(4): for x in range(6): list = [x, x + 6, x + 12] piglow.set(list, 20) sleep(0.05) piglow.set(list, 0) sleep(0.03)
import piglow import time piglow.auto_update = True print("Testing continuous set...") piglow.set(0, [100, 100, 100]) time.sleep(1) piglow.all(0) print("Testing list/list set...") piglow.set([0, 2, 4, 6, 8, 10, 12, 14, 16], [100, 100, 100, 100, 100, 100, 100, 100, 100]) time.sleep(1) piglow.all(0) print("Testing single value, multi LED set...") piglow.set([1, 3, 5, 7, 9, 11, 13, 15, 17], 100) time.sleep(1) piglow.all(0)
#!/usr/bin/env python import time import piglow i = 0 while True: print(i) piglow.all(0) piglow.set(i % 18, [15, 31, 63, 127, 255, 127, 63, 31, 15]) piglow.show() i += 1 #time.sleep(0.1)
#!/usr/bin/env python import time import piglow i = 0 while True: print(i) piglow.all(0) piglow.set(i % 18, [15, 31, 63, 127, 255, 127, 63, 31, 15]) piglow.show() i += 1 time.sleep(0.1)
#!/usr/bin/env python import piglow from time import sleep piglow.auto_update = True # blink 3 times BRIGHT_MAX = 20 bright = BRIGHT_MAX for count in range(4): for x in range(6): list = [x, x + 6, x + 12] piglow.set(list, bright) sleep(0.1) bright = 0 if bright == BRIGHT_MAX else BRIGHT_MAX # shine once for x in range(130): piglow.all(x) piglow.show() for x in reversed(range(130)): piglow.all(x) piglow.show()
#!/usr/bin/env python import piglow from time import sleep piglow.auto_update = True for count in range(4): for x in reversed(range(6)): arr = [x, x + 6, x + 12] piglow.set(arr, 20) sleep(0.05) piglow.set(arr, 0) sleep(0.03)
#!/usr/bin/env python import piglow from time import sleep piglow.auto_update = True tmp_arr = [] for count in range(4): for x in range(6): arr = [x, x + 6, x + 12] piglow.set(arr, 20) sleep(0.05) if len(tmp_arr) > 0: piglow.set(tmp_arr, 0) sleep(0.03) tmp_arr = arr
#!/usr/bin/env python import time import piglow i = 0 x = 0 while True: if i % 32 == 0: piglow.leg((x % 3), 64) x += 1 piglow.set(0, list(map(lambda x: x - 1 if x > 1 else 0, piglow.get()))) piglow.show() time.sleep(0.1) i += 1