本文整理汇总了Python中dotstar.Adafruit_DotStar.setPixelColor方法的典型用法代码示例。如果您正苦于以下问题:Python Adafruit_DotStar.setPixelColor方法的具体用法?Python Adafruit_DotStar.setPixelColor怎么用?Python Adafruit_DotStar.setPixelColor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dotstar.Adafruit_DotStar
的用法示例。
在下文中一共展示了Adafruit_DotStar.setPixelColor方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from dotstar import Adafruit_DotStar [as 别名]
# 或者: from dotstar.Adafruit_DotStar import setPixelColor [as 别名]
def main():
# set up audio input...
recorder = alsaaudio.PCM(alsaaudio.PCM_CAPTURE)
recorder.setchannels(CHANNELS)
recorder.setrate(RATE)
recorder.setformat(INFORMAT)
recorder.setperiodsize(FRAMESIZE)
# Set up off button
GPIO.setmode(GPIO.BCM)
GPIO.setup(23,GPIO.IN,pull_up_down = GPIO.PUD_UP)
# Initialize colors of each LED...
strip = Adafruit_DotStar(numpixels)
strip.begin()
for i in range(15):
time.sleep(float(1.0/float(i+1)))
strip.setBrightness(int(stripBright*(i+1)/15))
strip.setPixelColor(i,colors[i][0],colors[i][1],colors[i][2])
strip.setPixelColor(29-i,colors[29-i][0],colors[29-i][1],colors[29-i][2])
strip.show()
time.sleep(1)
# MAIN LOOP:
i=0
bigtime = 0.0
valsold = []
print "IN MAIN LOOP"
try:
while True:
# Check for off button press
on = GPIO.input(23)
if on == False:
shutdown(strip)
# Read music and get magnitudes for FRAMESIZE length
Y = getMagnitudes(recorder)
if Y != None:
# Update LED strip based on magnitudes
vals = controlLights(strip,Y,valsold)
# Update valsold list which is used by my smoothAvg function
# to make a running average of brightnesses rather than actual brightnesses
valsold.insert(0,vals)
if len(valsold) > 20:
valsold.pop()
if i % 1000 == 0:
print "TIME:",time.time()-bigtime
print "ITERATION: ",i
bigtime = time.time()
i+=1
except KeyboardInterrupt:
pass
示例2: rgbStrip
# 需要导入模块: from dotstar import Adafruit_DotStar [as 别名]
# 或者: from dotstar.Adafruit_DotStar import setPixelColor [as 别名]
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\
示例3: __init__
# 需要导入模块: from dotstar import Adafruit_DotStar [as 别名]
# 或者: from dotstar.Adafruit_DotStar import setPixelColor [as 别名]
class Blinkt:
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)
def to_rgb(self,r,g,b):
return (g << 16) + (r << 8) + b
def show(self, colour, pixel):
self.strip.setPixelColor(pixel, colour)
self.strip.show()
def show_all(self, colour):
for x in range(0,8):
self.strip.setPixelColor(x, colour)
self.strip.show()
示例4: rgbStripTest
# 需要导入模块: from dotstar import Adafruit_DotStar [as 别名]
# 或者: from dotstar.Adafruit_DotStar import setPixelColor [as 别名]
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;
示例5: color
# 需要导入模块: from dotstar import Adafruit_DotStar [as 别名]
# 或者: from dotstar.Adafruit_DotStar import setPixelColor [as 别名]
tail = -10 # Index of last 'off' pixel
color = 0xFF0000 # 'On' color (starts red)
pixels = 50
delay = .001
def makeColor(r, g, b):
return (r << 16) + (g << 8) + b
def colorWheel(wheelPos):
if wheelPos < 85:
return makeColor(wheelPos * 3, 255 - wheelPos * 3, 0)
elif wheelPos < 170:
wheelPos -= 85
return makeColor(0, wheelPos * 3, 255 - wheelPos * 3)
else:
wheelPos -= 170
return makeColor(255 - wheelPos * 3, 0, wheelPos * 3)
while True:
for j in reversed(range(pixels)):
for i in range(j):
strip.setPixelColor(i, 0xFF0000)
strip.show()
strip.setPixelColor(i, 0)
time.sleep(delay)
strip.setPixelColor(i, 0xFF0000)
示例6: abs
# 需要导入模块: from dotstar import Adafruit_DotStar [as 别名]
# 或者: from dotstar.Adafruit_DotStar import setPixelColor [as 别名]
pos = abs(mousepos) * scale
if pos > 1.0: break
lightpaint.dither(ledBuf, pos)
strip.show(ledBuf)
if btn() != pin_go: # Button released?
strip.show(clearBuf)
elif b == 2:
# Decrease paint duration
if speed_pixel > 0:
speed_pixel -= 1
duration = (min_time + time_range *
speed_pixel / (num_leds - 1))
strip.setPixelColor(speed_pixel, 0x000080)
strip.show()
startTime = time.time()
while (btn() == 2 and ((time.time() - startTime) <
rep_time)): continue
strip.clear()
strip.show()
elif b == 3:
# Increase paint duration (up to 10 sec maximum)
if speed_pixel < num_leds - 1:
speed_pixel += 1
duration = (min_time + time_range *
speed_pixel / (num_leds - 1))
strip.setPixelColor(speed_pixel, 0x000080)
strip.show()
startTime = time.time()
示例7: elif
# 需要导入模块: from dotstar import Adafruit_DotStar [as 别名]
# 或者: from dotstar.Adafruit_DotStar import setPixelColor [as 别名]
while True: # Loop forever
# rotate color through rainbow
if (color & 0xFF0000) and not (color & 0x0000FF):
color = color - 0x010000 # decrement red
color = color + 0x000100 # increment green
elif(color & 0x00FF00):
color = color - 0x000100 # decrement green
color = color + 0x000001 # increment blue
elif(color & 0x0000FF):
color = color - 0x000001 # decrement blue
color = color + 0x010000 # increment red
# Turn off old dot
strip.setPixelColor(dot, 0)
# Calculate wave based on time
now = time.time()
angle = angle_mult * (now - start)
amplitude = math.cos(now/mod_period)
wave = amplitude * math.cos(angle)
#dot = int(math.floor(((wave + 1.0)*(numpixels-1) + 1.0)/2.0))
#dot = int(((wave + 1.0)*(numpixels-1)/2.0 + 1.0)//2.0 + numpixels/2)
dot = int(((wave + 1.0)*(numpixels-1) + 1.0)//2.0)
# Turn on new dot
strip.setPixelColor(dot, color)
strip.show() # Refresh strip
#time.sleep(1.0 / 50) # Pause 20 milliseconds (~50 fps)
示例8: Adafruit_DotStar
# 需要导入模块: from dotstar import Adafruit_DotStar [as 别名]
# 或者: from dotstar.Adafruit_DotStar import setPixelColor [as 别名]
# 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.
head = 0 # Index of first 'on' pixel
tail = -20 # Index of last 'off' pixel
color = 0xFF0000 # 'On' color (starts red)
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 / 100) # 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
示例9: range
# 需要导入模块: from dotstar import Adafruit_DotStar [as 别名]
# 或者: from dotstar.Adafruit_DotStar import setPixelColor [as 别名]
r_start = 0xFF
g_start = 0x00
b_start = 0x00
for s in range(0x00,0xFF):
r = r_start - s
g = g_start + s
b = b_start
color = r*0x010000 + g*0x000100 + b*0x000001
time.sleep(delay)
head += 1
for i in range(31): #Step through all pixels in my led strip (1-30)
# strip.setPixelColor(i, color) # Turn on pixel #i
strip.setPixelColor(i, color + i * 0xFF / 32 + s + head) # Turn on pixel #i
strip.show() # Refresh strip
time.sleep(delay) # pause delay seconds
head += 1
#------------------#
# Green -> Blue
#------------------#
r_start = 0x00
g_start = 0xFF
b_start = 0x00
for s in range(0x00,0xFF):
示例10: startTimer
# 需要导入模块: from dotstar import Adafruit_DotStar [as 别名]
# 或者: from dotstar.Adafruit_DotStar import setPixelColor [as 别名]
active = False
# call function again
startTimer()
# initialize
init()
counter = 0
while True:
counter += 1
# flash one LED red if there is trouble connecting
if not active:
for num in range(1, LED_COUNT):
strip.setPixelColor(num, 0, 0, 0)
bri = math.fabs(math.sin(counter * 0.05))
strip.setPixelColor(0, int(255 * bri), 0, 0)
else:
# smooth fade in & out
for idx, hour in enumerate(precipHours):
bri = math.fabs(math.sin((counter + (idx * 25)) * 0.05))
if hour[0] == 'r':
precipColor = rain
elif hour[0] == 's':
precipColor = snow
strip.setPixelColor(hour[1], int(precipColor.r * bri), int(precipColor.g * bri), int(precipColor.b * bri))
strip.show()
time.sleep(1.0 / 50) # Pause 20 milliseconds (~50 fps)
示例11: Adafruit_DotStar
# 需要导入模块: from dotstar import Adafruit_DotStar [as 别名]
# 或者: from dotstar.Adafruit_DotStar import setPixelColor [as 别名]
#!/usr/bin/python
import time
import math
import array
from dotstar import Adafruit_DotStar
numpixels = 72 # Number of LEDs in strip
strip = Adafruit_DotStar(numpixels) # Use SPI (pins 10=MOSI, 11=SCLK)
strip.begin() # Initialize pins for output
strip.setBrightness(64) # Limit brightness to ~1/2 duty cycle
# Initialize CA, for now with 1 pixel
cells = array.array('B',(0,)*numpixels)
# Set strip colors and display them
for i in range(numpixels):
strip.setPixelColor(i, 0x000000)
strip.show() # Refresh strip
示例12: range
# 需要导入模块: from dotstar import Adafruit_DotStar [as 别名]
# 或者: from dotstar.Adafruit_DotStar import setPixelColor [as 别名]
#------------------#
r_start = 0xFF
g_start = 0x00
b_start = 0x00
for s in range(0x00,0xFF):
r = r_start - s
g = g_start + s
b = b_start
color = r*0x010000 + g*0x000100 + b*0x000001
for i in range(31): #Step through all pixels in my led strip (1-30)
# strip.setPixelColor(i, color) # Turn on pixel #i
strip.setPixelColor(i, color + i / 32 * 0xFF) # Turn on pixel #i
strip.show() # Refresh strip
time.sleep(delay) # pause delay seconds
#------------------#
# Green -> Blue
#------------------#
r_start = 0x00
g_start = 0xFF
b_start = 0x00
for s in range(0x00,0xFF):
示例13: Adafruit_DotStar
# 需要导入模块: from dotstar import Adafruit_DotStar [as 别名]
# 或者: from dotstar.Adafruit_DotStar import setPixelColor [as 别名]
#!/usr/bin/python
from dotstar import Adafruit_DotStar
LED_COUNT = 7
datapin = 10
clockpin = 11
strip = Adafruit_DotStar(LED_COUNT, datapin, clockpin)
strip.begin()
for num in range(1, LED_COUNT):
strip.setPixelColor(num, 0, 0, 0)
strip.show()
示例14: color
# 需要导入模块: from dotstar import Adafruit_DotStar [as 别名]
# 或者: from dotstar.Adafruit_DotStar import setPixelColor [as 别名]
# Append "order='gbr'" to declaration for proper colors w/older DotStar strips)
strip.begin() # Initialize pins for output
strip.setBrightness(65) # 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 = 10 # Index of first 'on' pixel
tail = 0 # Index of last 'off' pixel
color = 0xFF0000 # 'On' color (starts red)
step = -0x010000
while True: # Loop forever
for i in range(31):
strip.setPixelColor(i, color) # Turn on 'head' pixel
strip.show() # Refresh strip
time.sleep(1.0 / 400) # 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
# color = (0.99*color)
if (color>=0xFF0000): step = -0x010000
示例15: Adafruit_DotStar
# 需要导入模块: from dotstar import Adafruit_DotStar [as 别名]
# 或者: from dotstar.Adafruit_DotStar import setPixelColor [as 别名]
# Set the strip to all white at lowest brightness, and slowly ramp up.
import time
from dotstar import Adafruit_DotStar
WHITE = 0xFFFFFF
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
# Open log file.
f = open('powerlog.txt', 'w')
f.write("Brightness\tVoltage\n")
for p in range(n_pixels):
strip.setPixelColor(p, WHITE)
for b in range(256):
#print b
# Set the brightness.
strip.setBrightness(b)
strip.show() # Refresh strip
# Prompt user for data entry.
answer = raw_input(str(b)+' ')
# Log it.
f.write(str(b)+"\t"+answer+"\n")
f.flush()
# Wait a fraction of a second to help ensure that the write completes,
# in case the next brightness level crashes the system.
time.sleep(0.1)