本文整理汇总了Python中dotstar.Adafruit_DotStar类的典型用法代码示例。如果您正苦于以下问题:Python Adafruit_DotStar类的具体用法?Python Adafruit_DotStar怎么用?Python Adafruit_DotStar使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Adafruit_DotStar类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: init_strip
def init_strip( numpixels , brightness , datapin , clockpin):
strip = Adafruit_DotStar(numpixels , 125000000)
#strip = Adafruit_DotStar(numpixels, datapin , clockpin)
#Initialize pins for output
strip.begin()
strip.setBrightness(brightness)
return strip
示例2: __init__
def __init__(self, host):
self.host = host
self.strip = Adafruit_DotStar(numpixels, datapin, clockpin)
self.strip.begin()
self.strip.setBrightness(32)
green = self.to_rgb(0,255,0)
self.show_all(green)
示例3: rgbStrip
def rgbStrip(R, G, B):
numpixels = 30; # Number of LEDs in strip
# strip = Adafruit_DotStar(numpixels, rgb_strip_datapin, rgb_strip_clockpin)
strip = Adafruit_DotStar(numpixels) # SPI @ ~32 MHz
strip.begin() # Initialize pins for output
strip.setBrightness(64) # Limit brightness to ~1/4 duty cycle
# Runs 10 LEDs at a time along strip, cycling through red, green and blue.
# This requires about 200 mA for all the 'on' pixels + 1 mA per 'off' pixel.
led = 0 # Index of first 'on' pixel
while (led != 30): # Loop for each light
strip.setPixelColor(led, R, G, B) # Set pin color
strip.show() # Refresh strip
led += 1 # Advance head position\
示例4: __init__
def __init__(self, kill_event, loop_time=1.0 / 60.0):
self.status = "INIT"
self.q = Queue()
self.kill_event = kill_event
self.timeout = loop_time
self.baudrate = BAUDRATE
self.dev = DEVICE
self.strip = Adafruit_DotStar(NUMPIXELS, DATAPIN, CLOCKPIN)
self.strip.begin()
self.strip.setBrightness(255)
self.serial = serial.Serial(self.dev)
self.serial.baudrate = 115200
# Initial state
self.send_elevator_command(ELEVATOR_DOWN)
self.status = "DOWN"
self.set_lights(OFF)
super(Elevator, self).__init__()
示例5: __init__
def __init__(self, FreqAverage=5, Path="pov/", start=""):
threading.Thread.__init__(self)
self.datapin = 2 # GPIO-Numbering!
self.clockpin = 3 # GPIO-Numbering!
self.strip = Adafruit_DotStar(0, self.datapin, self.clockpin)
# Notice the number of LEDs is set to 0. This is on purpose...we're asking
# the DotStar module to NOT allocate any memory for this strip...we'll handle
# our own allocation and conversion and will feed it 'raw' data.
self.strip.begin() # Initialize pins for output
self.empty_array=bytearray(60*4) # prepare empty-flash
for x in range(60):
self.empty_array[x*4]=0xFF
self.empty_array[x*4+1]=0x00
self.empty_array[x*4+2]=0x00
self.empty_array[x*4+3]=0x00
self.povPath=Path
self.povFile = start
self.size=[0,0]
self.FAverage=FreqAverage
self.actPeriod=0
self.freq = get_freq.freqThread(NAverage=self.FAverage) # initialize frequency-thread
self.running=False # is Thread displaying a pov-File?
self.NEWrunning=False # want to stop and start new?
self.active=True # is Thread active? (& playing OR waiting to play) -> only False if quitting main.
self.pause=False
self.pos=0
self.loading=False # loading? --> main waits for finishing loading-process
if start!="":
self.running=True
else:
self.off()
self.start()
示例6: Copyright
#!/usr/bin/python
# strip.py - Declare & initialize strip using dotstar.c library
#
# Copyright (C) 2017 Dan Jones - https://plasmadan.com
#
# Full project details here:
# https://github.com/plasmadancom/Raspberry-Pi-Relay-APA102-LED-Controller
# https://www.avforums.com/threads/ongoing-plasmadans-living-room-cinema-office-build.1992617/
#
# -----------------------------------------------------------------------------
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
# -----------------------------------------------------------------------------
# Import dependancies
from config import *
from dotstar import Adafruit_DotStar # Must be in same directory. Source: https://learn.adafruit.com/adafruit-dotstar-leds
strip = Adafruit_DotStar(numpixels, spi, order=rgb_order) # Declare strip. See https://learn.adafruit.com/adafruit-dotstar-leds
strip.begin() # Initialize pins for output
示例7: Adafruit_DotStar
# Persistence-of-vision (POV) example for Adafruit Dot Star RGB LED strip.
# Loads image, displays column-at-a-time on LEDs at very high speed,
# suitable for naked-eye illusions.
# See strandtest.py for a much simpler example script.
# See image-paint.py for a slightly simpler light painting example.
import Image
from dotstar import Adafruit_DotStar
filename = "hello.png" # Image file to load
# Here's how to control the strip from any two GPIO pins:
datapin = 23
clockpin = 24
strip = Adafruit_DotStar(0, datapin, clockpin)
# Notice the number of LEDs is set to 0. This is on purpose...we're asking
# the DotStar module to NOT allocate any memory for this strip...we'll handle
# our own allocation and conversion and will feed it 'raw' data.
# So we'll write directly to the pixel data buffer. Data is not necessarily
# in RGB order -- current DotStars use BRG order, and older ones are GBR.
# Additionally, byte 0 of each 4-byte pixel is always 0xFF, so the RGB
# offsets are always in range 1-3.
# Here's the offsets for current (2015+) strips:
rOffset = 2
gOffset = 3
bOffset = 1
# For older strips, change values to 3, 1, 2
# This is ONLY necessary because we're raw-writing; for normal setPixelColor
# use, offsets can be changed with the 'order' keyword (see strandtest.py).
示例8: Adafruit_DotStar
#!/usr/bin/python
# Test the power supply handling of large current draw transients.
# Set the strip to all white, and strobe it on and off.
import time
from dotstar import Adafruit_DotStar
WHITE = 0xFFFFFF # 8-bit GRB
MAX_BRIGHTNESS = 255
n_pixels = 72 # Number of LEDs in strip
strip = Adafruit_DotStar(n_pixels) # Use SPI (pins 10=MOSI, 11=SCLK)
strip.begin() # Initialize pins for output
frequency = 12 # Hz
period = 1.0/frequency # seconds
duty_cycle = 0.125
on_period = duty_cycle * period
off_period = period - on_period
for p in range(n_pixels):
strip.setPixelColor(p, WHITE)
while True:
# Turn strobe on.
strip.setBrightness(MAX_BRIGHTNESS)
strip.show()
time.sleep(on_period)
# Turn strobe off.
strip.setBrightness(0)
strip.show()
time.sleep(off_period)
示例9: rgbStripTest
def rgbStripTest():
numpixels = 30; # Number of LEDs in strip
# strip = Adafruit_DotStar(numpixels, datapin, clockpin)
strip = Adafruit_DotStar(numpixels, 12000000) # SPI @ ~32 MHz
strip.begin() # Initialize pins for output
strip.setBrightness(64) # Limit brightness to ~1/4 duty cycle
# Runs 10 LEDs at a time along strip, cycling through red, green and blue.
# This requires about 200 mA for all the 'on' pixels + 1 mA per 'off' pixel.
head = 0 # Index of first 'on' pixel
tail = -10 # Index of last 'off' pixel
color = 0xFF0000 # 'On' color (starts red)
repeat = 0
while True: # Loop forever
strip.setPixelColor(head, color) # Turn on 'head' pixel
strip.setPixelColor(tail, 0) # Turn off 'tail'
strip.show() # Refresh strip
time.sleep(1.0 / 50) # Pause 20 milliseconds (~50 fps)
head += 1 # Advance head position
if(head >= numpixels): # Off end of strip?
head = 0 # Reset to start
color >>= 8 # Red->green->blue->black
if(color == 0): color = 0xFF0000 # If black, reset to red
tail += 1 # Advance tail position
if(tail >= numpixels):
tail = 0 # Off end? Reset
repeat += 1
if(repeat == 10):
rgbStripOff(strip)
break;
示例10: Adafruit_DotStar
import sys
if sys.platform != "darwin":
from dotstar import Adafruit_DotStar
import RPi.GPIO as GPIO
LED=16
IRLED=12
datapin = 10
clockpin = 11
numpixels = 180 # Number of LEDs in strip
if sys.platform != "darwin":
strip = Adafruit_DotStar(numpixels, datapin, clockpin, bitrate=4500, order="bgr")
strip.begin() # Initialize pins for output
strip.setBrightness(64) # Limit brightness to ~1/4 duty cycle
head = 0 # Index of first 'on' pixel
tail = -10 # Index of last 'off' pixel
color = 0xFF0000 # 'On' color (starts red)
def makeColor(r, g, b):
#print "makecolor", r, g, b
return (r << 16) + (g << 8) + b
def colorWheel(wheelPos):
"""
0 is red, 85 is green, 170 is blue
"""
if wheelPos < 85:
示例11: main
def main():
# Build playlist of songs
os.system("rm -f /home/pi/playlist.pls; find " + song_location + " | grep 'flac\|ogg\|mp3' | shuf > playlist.pls")
global num_lines
try:
num_lines = sum(1 for line in open('playlist.pls'))
except:
num_lines = 0
turnOff()
if num_lines == 0:
demoMode() # No file/Empty file. Do demo mode!
while True: # Loops continuously until unplugged
queueNext()
turnOff() # Currently an issue with skipping back, should be a nonissue in the future.
if mixer.music.get_busy():
mixer.music.stop()
os.system('umount /mnt/usb; umount /dev/sdb1')
turnOff()
GPIO.cleanup()
def mountDevice():
os.system('mount /dev/sdb1 /mnt/usb')
if __name__ == "__main__":
# Wow this is pretty ugly - I'm in a hurry, though.
mountDevice()
strip = Adafruit_DotStar(numPixels, datapin, clockpin)
strip.begin()
strip.setBrightness(64)
mixer.init(48000, -16, 1, 1024)
main()
示例12: colors
# and blue and to forward data down the line. By limiting the number
# and color of LEDs, it's reasonably safe to power a couple meters off
# USB. DON'T try that with other code!
# This code has one LED that runs through the strip and changes colors (through fading) and all the other leds fading through all colors.
import time
from dotstar import Adafruit_DotStar
numpixels = 30 # Number of LEDs in strip
# Here's how to control the strip from any two GPIO pins:
datapin = 16
clockpin = 12
#strip = Adafruit_DotStar(numpixels, datapin, clockpin)
strip = Adafruit_DotStar(numpixels, datapin, clockpin,order='bgr')
# Alternate ways of declaring strip:
# strip = Adafruit_DotStar(numpixels) # Use SPI (pins 10=MOSI, 11=SCLK)
# strip = Adafruit_DotStar(numpixels, 32000000) # SPI @ ~32 MHz
# strip = Adafruit_DotStar() # SPI, No pixel buffer
# strip = Adafruit_DotStar(32000000) # 32 MHz SPI, no pixel buf
# See image-pov.py for explanation of no-pixel-buffer use.
# Append "order='gbr'" to declaration for proper colors w/older DotStar strips)
strip.begin() # Initialize pins for output
strip.setBrightness(32) # Limit brightness to ~1/4 duty cycle
# Runs 10 LEDs at a time along strip, cycling through red, green and blue.
# This requires about 200 mA for all the 'on' pixels + 1 mA per 'off' pixel.
示例13: Adafruit_DotStar
# Simple strand test for Adafruit Dot Star RGB LED strip.
# This is a basic diagnostic tool, NOT a graphics demo...helps confirm
# correct wiring and tests each pixel's ability to display red, green
# and blue and to forward data down the line. By limiting the number
# and color of LEDs, it's reasonably safe to power a couple meters off
# USB. DON'T try that with other code!
import time
from dotstar import Adafruit_DotStar
numpixels = 180 # Number of LEDs in strip
# Here's how to control the strip from any two GPIO pins:
datapin = 10
clockpin = 11
strip = Adafruit_DotStar(numpixels, datapin, clockpin)
# Alternate ways of declaring strip:
# strip = Adafruit_DotStar(numpixels) # Use SPI (pins 10=MOSI, 11=SCLK)
# strip = Adafruit_DotStar(numpixels, 32000000) # SPI @ ~32 MHz
# strip = Adafruit_DotStar() # SPI, No pixel buffer
# strip = Adafruit_DotStar(32000000) # 32 MHz SPI, no pixel buf
# See image-pov.py for explanation of no-pixel-buffer use.
# Append "order='gbr'" to declaration for proper colors w/older DotStar strips)
strip.begin() # Initialize pins for output
strip.setBrightness(64) # Limit brightness to ~1/4 duty cycle
# Runs 10 LEDs at a time along strip, cycling through red, green and blue.
# This requires about 200 mA for all the 'on' pixels + 1 mA per 'off' pixel.
示例14: Adafruit_DotStar
numpixels_F = 72+67+69 # Number of LEDs in strip
numpixels_R = 80
datapin_R_RGB = 16 # 36 Physical, 16 GPIO
clockpin_R_RGB = 20 # 38 Physical, 20 GPIO
datapin_R_W = 25 # 22 Physical
clockpin_R_W = 12 # 32 Physical
datapin_F_RGB = 22 # 15 Physical
clockpin_F_RGB = 18 # 12 Physical
datapin_F_W = 17 # 11 Physical
clockpin_F_W = 27 # 13 Physical
# Initialise without image buffers, sending data direct for speed
# bytearray order: FF B G R
led_r_rgb = Adafruit_DotStar(0, datapin_R_RGB, clockpin_R_RGB)
led_r_w = Adafruit_DotStar(0, datapin_R_W, clockpin_R_W)
led_f_rgb = Adafruit_DotStar(0, datapin_F_RGB, clockpin_F_RGB)
led_f_w = Adafruit_DotStar(0, datapin_F_W, clockpin_F_W)
# Calculate gamma correction table, makes mid-range colors look 'right'
gamma = bytearray(256)
for i in range(256):
gamma[i] = int(pow(float(i) / 255.0, 2.7) * 255.0 + 0.5)
# Initialise LED strips
offBytes = bytearray(numpixels_F * 4)
for i in range(0, numpixels_F*4, 4):
offBytes[i] = 0xFF
offBytes[i+1] = 0x0
示例15: Adafruit_DotStar
# Light-painting example for Adafruit Dot Star RGB LED strip.
# Loads image, displays column-at-a-time on LEDs at a reasonable speed
# for long exposure photography.
# See strandtest.py for a much simpler example script.
# See image-pov.py for a faster persistence-of-vision example.
import Image
from dotstar import Adafruit_DotStar
numpixels = 30 # Number of LEDs in strip
filename = "hello.png" # Image file to load
# Here's how to control the strip from any two GPIO pins:
datapin = 23
clockpin = 24
strip = Adafruit_DotStar(numpixels, datapin, clockpin)
strip.begin() # Initialize pins for output
# Load image in RGB format and get dimensions:
print "Loading..."
img = Image.open(filename).convert("RGB")
pixels = img.load()
width = img.size[0]
height = img.size[1]
print "%dx%d pixels" % img.size
if height > strip.numPixels():
height = strip.numPixels()
# Calculate gamma correction table, makes mid-range colors look 'right':