You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

153 lines
4.0 KiB
Python

#!/usr/bin/env python
#defines appearance for LEDs, such as bouncing effect, circular effect.
import Adafruit_WS2801
import Adafruit_GPIO.SPI as SPI
import time
# count of pixels:
PIXEL_COUNT = 19
# specify a hardware SPI connection on /dev/spidev0.0:
SPI_PORT = 0
SPI_DEVICE = 0
pixels = Adafruit_WS2801.WS2801Pixels(PIXEL_COUNT, spi=SPI.SpiDev(SPI_PORT, SPI_DEVICE))
# colors of each character
color_guru = [146, 200, 0] # purple
color_pirate = [255, 0, 200] # yellow
color_announcer= [0, 100, 200] # aqua blue
color_activation= [255, 255, 255] # white
def leds_color_intensity(color, intensity):
# color: a list of 3 rgb components 0 to 255
# intensity: between 0 and 1
# pixN: number of pixels
r = color[0]
g = color[1]
b = color[2]
for i in range(PIXEL_COUNT):
pixels.set_pixel_rgb(i,
int(r*intensity),
int(g*intensity),
int(b*intensity) ) # Set the RGB color (0-255) of pixel i
pixels.show()
# LEDs grow and shrink
def leds_color_length(color, intensity):
# color: a list of 3 rgb components 0 to 255
# intensity: between 0 and 1
# pixN: number of pixels
r = color[0]
g = color[1]
b = color[2]
led_length = int(PIXEL_COUNT * intensity)
for i in range(led_length):
pixels.set_pixel_rgb(i,
int(r),
int(g),
int(b) ) # Set the RGB color (0-255) of pixel i
time.sleep(0.01)
pixels.show()
pixels.clear()
# LEDS for pirate
def leds_pirate_blink(color):
# color: a list of 3 rgb components 0 to 255
# pixN: number of pixels
r = color[0]
g = color[1]
b = color[2]
while True:
pixels.clear()
pixels.show()
time.sleep(0.02)
for i in range(PIXEL_COUNT):
pixels.set_pixel_rgb(i,
int(r),
int(g),
int(b) ) # Set the RGB color (0-255) of pixel i
pixels.show()
time.sleep(0.01)
def leds_pirate_circle(color):
# color: a list of 3 rgb components 0 to 255
# pixN: number of pixels
r = color[0]
g = color[1]
b = color[2]
while True:
for i in range(PIXEL_COUNT):
pixels.set_pixel_rgb(i,
int(r),
int(g),
int(b) ) # Set the RGB color (0-255) of pixel i
pixels.show()
time.sleep(0.01)
pixels.clear()
pixels.show()
time.sleep(0.3)
def leds_pirate_bounce(color):
# color: a list of 3 rgb components 0 to 255
# pixN: number of pixels
r = color[0]
g = color[1]
b = color[2]
leds = list(range(PIXEL_COUNT))+ (list(range(PIXEL_COUNT))[::-1])
n = 0
while True:
n = n + 1
for i in leds:
pixels.set_pixel_rgb(i,
int(r),
int(g),
int(b) ) # Set the RGB color (0-255) of pixel i
pixels.show()
time.sleep(0.01)
pixels.clear()
pixels.show()
time.sleep(0.3)
if n > 3:
break
# activation mode is one white leds bounce
def leds_activation(color):
# color: a list of 3 rgb components 0 to 255
# pixN: number of pixels
r = color[0]
g = color[1]
b = color[2]
leds = list(range(PIXEL_COUNT))+ (list(range(PIXEL_COUNT))[::-1])
n = 0
while True:
n = n + 1
for i in leds:
pixels.set_pixel_rgb(i,
int(r),
int(g),
int(b) ) # Set the RGB color (0-255) of pixel i
pixels.show()
time.sleep(0.01)
pixels.clear()
pixels.show()
time.sleep(0.1)
if n > 0:
break
pixels.clear() # Clear all the pixels to turn them off.