def __init__(self, size): if RUNNING_ON_PI: self._pixels = adafruit_ws2801.WS2801(board.D11, board.D10, size, auto_write=False) super().__init__(size) self._leds = [Color(rgb=(0, 0, 0)) for _ in range(len(self._leds))] self.DisplayLine()
def _init_led(self): self.led = adafruit_ws2801.WS2801( board.SCLK, board.MOSI, self.leds, brightness=self.brightness() )
import time from timeloop import Timeloop import datetime from datetime import timedelta tl = Timeloop() checkdate = (datetime.date.today() - datetime.timedelta(1)).strftime("%d-%b-%Y") odata = board.MOSI oclock = board.SCK numleds = 50 bright = 1.0 leds = adafruit_ws2801.WS2801(oclock, odata, numleds, brightness=bright, auto_write=False) leds.fill((0, 0, 255)) leds.show() print(checkdate) EMAIL = '*****@*****.**' PASSWORD = '******' SERVER = 'mail.rich-path.com' mail = imaplib.IMAP4_SSL(SERVER) mail.login(EMAIL, PASSWORD) mail.select('inbox')
K1 = 16 GPIO.setmode(GPIO.BCM) GPIO.setup(K1, GPIO.OUT) GPIO.output(K1, GPIO.LOW) #for i in range(10): # GPIO.output(led, GPIO.HIGH) # time.sleep(0.2) # GPIO.output(led, GPIO.LOW) # time.sleep(0.2) time.sleep(0.2) darkred = 0x100000 pixels = ws2801.WS2801(board.SCLK, board.MOSI, 41, brightness=1.0, auto_write=True) pixels.fill((0x80, 0x30, 0x10)) pixels.show() time.sleep(5) pixels.fill((0x10, 0x30, 0x80)) pixels.show() time.sleep(5) GPIO.cleanup()
from RPi import GPIO as io import time import board import adafruit_ws2801 import random import colorsys import subprocess leds = adafruit_ws2801.WS2801(board.SCLK, board.MOSI, 32) pir = 14 monitor_status = 0 def setup(): io.setmode(io.BCM) io.setup(pir, io.IN, io.PUD_DOWN) print("Sensor initializing . . .") time.sleep(2) # Give sensor time to startup print("Active") counter = 0 def hsv2rgb(h, s, v): return tuple(round(i * 255) for i in colorsys.hsv_to_rgb(h, s, v)) def random_color(): return random.randrange(0, 7) * 32
def init(): return adafruit_ws2801.WS2801(oclock, odata, numleds, brightness=bright, auto_write=False)
import time import board import pulseio import touchio import adafruit_ws2801 import adafruit_fancyled.adafruit_fancyled as fancy led = pulseio.PWMOut(board.D13, frequency=5000, duty_cycle=128) led0 = pulseio.PWMOut(board.D0, frequency=5000, duty_cycle=128) strip = adafruit_ws2801.WS2801(board.D3, board.D4, 7, auto_write=False) touch = touchio.TouchIn(board.A0) throbbing = True goingup = True valduty = 5 wason = False # across the rainbow grad = [(0.0, 0xFF0000), (0.33, 0x00FF00), (0.67, 0x0000FF), (1.0, 0xFF0000)] palette = fancy.expand_gradient(grad, 20) offset = 0.25 while True: if throbbing: if goingup: valduty = valduty + 1 if valduty > 250: goingup = False else:
import random import time import board import adafruit_ws2801 as pixels odata = board.MOSI oclock = board.SCK def random_colour(): return random.randrange(0, 7) * 32 leds = pixels.WS2801(oclock, odata, 25, brightness=1.0, auto_write=True) while True: for idx in range(len(leds)): leds[idx] = (random_colour(), random_colour(), random_colour()) time.sleep(.15)
import adafruit_ws2801 import struct log = logging.getLogger("ColorsetPlugin") class Colorset(BasePlugin): topic = "{}led/color".format(settings.MQTT_TOPIC) def __init__(self): self._led = adafruit_ws2801.WS2801(board.SCLK, board.MOSI, settings.LED_COUNT, brightness=1.0, auto_write=False) def on_message(self, topic, payload): r, g, b, start, end = struct.unpack("BBBBB", payload) for i in range(start, end): try: self._led[i] = (r, g, b) except Exception as e: pass self._led.show() leds = adafruit_ws2801.WS2801(board.D2, board.D0, 25) leds.fill((0x80, 0, 0))
def __init__(self): self._led = adafruit_ws2801.WS2801(board.SCLK, board.MOSI, settings.LED_COUNT, brightness=1.0, auto_write=False)
from led_controller.pattern_animator import PatternAnimator from led_controller.pattern_animator_none import PatternAnimatorNone from led_controller.pattern_animator_blink import PatternAnimatorBlink from led_controller.pattern_animator_chase import PatternAnimatorChase import logging from api.gen.base.models.led_pattern import LEDPattern from api.gen.base.models.blink_led_pattern import BlinkLEDPattern from api.gen.base.models.chase_led_pattern import ChaseLEDPattern import threading __LOG = logging.getLogger(__name__) __pattern_animator = None __pattern_lock = threading.Lock() __leds = adafruit_ws2801.WS2801(board.SCK, board.MOSI, PatternAnimator.LED_COUNT, auto_write=False) # failsafe __leds.deinit() __leds = adafruit_ws2801.WS2801(board.SCK, board.MOSI, PatternAnimator.LED_COUNT, auto_write=False) __leds.brightness = 1 __leds.fill((0, 0, 0)) def start_pattern_display(led_pattern: LEDPattern): with __pattern_lock: global __pattern_animator
import argparse import json import adafruit_ws2801 from bisect import bisect_left from ast import literal_eval as make_tuple #Definitions oclock = board.SCLK odata = board.MOSI bright = 1.0 data = json.loads(sys.argv[1]) # receive data from node_helper #Initialise LEDs if "LEDType" in data and "LEDCount" in data: if data["LEDType"] == "WS2801": leds = adafruit_ws2801.WS2801(oclock, odata, data["LEDCount"], brightness=bright, auto_write=False) #Start Effect if "options" in data: #is there a defined effect? start_effect(leds, strEffect=data["effect"], strActiveColor=data["activeColor"], arrColors=data["colors"], arrOptions=data["options"]) #start defined effect elif "effect" in data: start_effect(leds, strEffect=data["effect"], strActiveColor=data["activeColor"], arrColors=data["colors"], arrOptions=[""]) #Reactivate party mode in case it was on before effect #if data["partyMode"]: # start party mode #Deinitialise LEDs if "effect" in data: # is there a defined effect? if data["effect"] == "lightOff": deinitialise_LED_strip(leds)
def __init__(self, led_amount=32): self.led_amount = led_amount self.leds = adafruit_ws2801.WS2801(board.SCLK, board.MOSI, self.led_amount) self.leds.fill((0, 0, 0))
def __init__(self, num_leds, s0, s45, s90, s135, s180, s225, s270, s315, init_philips_hue=False, philips_hue_ip="0.0.0.0", light_names=None): # if no light names are specified, replace with empty list if light_names is None: light_names = [] # get total number of leds by adding together all edge lengths self.num_leds = sum([ s0.length, s45.length, s90.length, s135.length, s180.length, s225.length, s270.length, s315.length ]) # try importing the adafruit library and initialize strip. If it fails, demo mode will be used and the strip # is just a list of color tuples try: if six.PY3: import adafruit_ws2801 as af import board self.leds = af.WS2801(board.SCK, board.MOSI, self.num_leds, auto_write=False) elif six.PY2: import RPi.GPIO as GPIO import Adafruit_WS2801 as af import Adafruit_GPIO.SPI as SPI SPI_PORT = 0 SPI_DEVICE = 0 self.leds = af.WS2801Pixels(self.num_leds, spi=SPI.SpiDev( SPI_PORT, SPI_DEVICE), gpio=GPIO) self.demo = False except ImportError: print("running in demo mode") time.sleep(3) self.demo = True self.leds = [(0, 0, 0)] * self.num_leds # set up philips hue, if fails, features won't be used self.phue_setup_done = False if init_philips_hue: try: import phue # import the python hue library try: self.phuebridge = phue.Bridge( philips_hue_ip) # setup bridge self.phuebridge.connect() # connect to bridge self.phue_light_names = [] # store all found lights all_lights = self.phuebridge.get_light_objects( ) # retrieve all light objects from bridge # cycle through all lights, check if light name in list supplied to init function, then remove from # user supplied list and append to list from above for light in all_lights: if light.name in light_names: light_names.remove(light.name) self.phue_light_names.append(light.name) # if all lights were found, phue_setup_done set to true if len(light_names) == 0: self.phue_setup_done = True except phue.PhueRegistrationException: print( "Registration Error, link button not pressed in the past 30 seconds" ) pass except phue.PhueRequestTimeout: print("Connection error") pass except ImportError: print("Error importing phue") pass # initialize list containing all color values self.colors = [] for i in range(self.num_leds): self.colors.append((0, 0, 0)) # associate supplied edges with correct attributes self.north = s0 self.north_east = s45 self.east = s90 self.south_east = s135 self.south = s180 self.south_west = s225 self.west = s270 self.north_west = s315 # initialize empty lists for various sets self.all_edges_in_order = None self.ceiling_edges_clockwise = None self.vertical_edges_up = None
import queue import time import threading import random import board import adafruit_ws2801 from flask import Flask, render_template, request, jsonify NUM_LEDS = 25 leds = adafruit_ws2801.WS2801(board.SCK, board.MOSI, NUM_LEDS, brightness=1.0, auto_write=False) q = queue.Queue() def queue_worker(): while True: print("Queue size: %d" % q.qsize()) item = q.get() leds.fill(item) leds.show() q.task_done() time.sleep(1) threading.Thread(target=queue_worker, daemon=True).start() COLOURS = { "Red": 0xff0000,