当前位置: 首页>>代码示例>>Python>>正文


Python Adafruit_DotStar.show方法代码示例

本文整理汇总了Python中dotstar.Adafruit_DotStar.show方法的典型用法代码示例。如果您正苦于以下问题:Python Adafruit_DotStar.show方法的具体用法?Python Adafruit_DotStar.show怎么用?Python Adafruit_DotStar.show使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在dotstar.Adafruit_DotStar的用法示例。


在下文中一共展示了Adafruit_DotStar.show方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: from dotstar import Adafruit_DotStar [as 别名]
# 或者: from dotstar.Adafruit_DotStar import show [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
开发者ID:mjmartin23,项目名称:MusicLEDController,代码行数:56,代码来源:lights2.py

示例2: rgbStrip

# 需要导入模块: from dotstar import Adafruit_DotStar [as 别名]
# 或者: from dotstar.Adafruit_DotStar import show [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\
开发者ID:mikauhsoj,项目名称:IoTHomeAutomationPyScripts,代码行数:19,代码来源:main.py

示例3: __init__

# 需要导入模块: from dotstar import Adafruit_DotStar [as 别名]
# 或者: from dotstar.Adafruit_DotStar import show [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()
开发者ID:alexellis,项目名称:datacenter-sensor,代码行数:20,代码来源:blinkt.py

示例4: rgbStripTest

# 需要导入模块: from dotstar import Adafruit_DotStar [as 别名]
# 或者: from dotstar.Adafruit_DotStar import show [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;
开发者ID:mikauhsoj,项目名称:IoTHomeAutomationPyScripts,代码行数:39,代码来源:main.py

示例5: scale

# 需要导入模块: from dotstar import Adafruit_DotStar [as 别名]
# 或者: from dotstar.Adafruit_DotStar import show [as 别名]
			print hue
			print sat
			print val
			print ""
			
			h = scale(hue, 0, 255, 0, 1)
			s = scale(sat, 0, 255, 0, 1)
			v = scale(val, 0, 255, 0, 1)
			
			r,g,b = colorsys.hsv_to_rgb(h,s,v)
			
			
			print r
			print g
			print b
			print ""
			
			r = int(scale(r, 0, 1, 0, 255))
			g = int(scale(g, 0, 1, 0, 255))
			b = int(scale(b, 0, 1, 0, 255))
			
			print r
			print g
			print b
			
			color = strip.Color(g,r,b)
			
			for i in range(numpixels):
				strip.setPixelColor(i, color)
			strip.show()
开发者ID:Coolbots7,项目名称:CB_SmartHouse,代码行数:32,代码来源:caseLeds.py

示例6: elif

# 需要导入模块: from dotstar import Adafruit_DotStar [as 别名]
# 或者: from dotstar.Adafruit_DotStar import show [as 别名]
	# 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)

开发者ID:HowardALandman,项目名称:HForce,代码行数:30,代码来源:WaveWand.py

示例7: bytearray

# 需要导入模块: from dotstar import Adafruit_DotStar [as 别名]
# 或者: from dotstar.Adafruit_DotStar import show [as 别名]
# 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':
gamma = bytearray(256)
for i in range(256):
    gamma[i] = int(pow(float(i) / 255.0, 2.7) * 255.0 + 0.5)

print "Displaying..."
while True:  # Loop forever

    for x in range(width):  # For each column of image...
        for y in range(height):  # For each pixel in column...
            value = pixels[x, y]  # Read pixel in image
            strip.setPixelColor(
                y,  # Set pixel in strip
                gamma[value[0]],  # Gamma-corrected red
                gamma[value[1]],  # Gamma-corrected green
                gamma[value[2]],
            )  # Gamma-corrected blue
        strip.show()  # Refresh LED strip
开发者ID:matthiasplappert,项目名称:lego-elevator,代码行数:31,代码来源:image-paint.py

示例8: int

# 需要导入模块: from dotstar import Adafruit_DotStar [as 别名]
# 或者: from dotstar.Adafruit_DotStar import show [as 别名]
   while presentation_time > int(time.time() * 1000) - start_time:
     oled._buffer = buffer_cache[frame_index % 10]  
     oled.display() 
     time.sleep(0.0001)
   
   # Set Drive
   
   #Command 01 = Sequence run vpos start
   vpos_steps = int(meta[2]*drive_max_steps)
   arduinoSerial.write(chr(0x40 + ((vpos_steps >> 12) & 0x3F)) + chr((vpos_steps >> 6) & 0x3F) + chr(vpos_steps & 0x3F))
   
   # Set LED Strips
   
   # print(str(frame_index) + ", " + sequence_led_f_www[frame_index])
   if sequence_led_f_www[frame_index] is not None:
     led_f_w.show(sequence_led_f_www[frame_index])
   if sequence_led_f_rgb[frame_index] is not None:
     led_f_rgb.show(sequence_led_f_rgb[frame_index])
   if sequence_led_r_www[frame_index] is not None:
     led_r_w.show(sequence_led_r_www[frame_index])
   if sequence_led_r_rgb[frame_index] is not None:
     led_r_rgb.show(sequence_led_r_rgb[frame_index])
   
   if (log_to_console):
     print("Frame " + str(frame_index) + " vpos_steps " + str(vpos_steps))
 
 # Sequence End
 
 for strip in [led_r_rgb, led_r_w, led_f_rgb, led_f_w]:
   strip.show(offBytes)
 
开发者ID:tobyspark,项目名称:TekonOneThree-Controller,代码行数:32,代码来源:tektononethree.py

示例9: bytearray

# 需要导入模块: from dotstar import Adafruit_DotStar [as 别名]
# 或者: from dotstar.Adafruit_DotStar import show [as 别名]
gamma = bytearray(256)
for i in range(256):
	gamma[i] = int(pow(float(i) / 255.0, 2.7) * 255.0 + 0.5)

# Allocate list of bytearrays, one for each column of image.
# Each pixel REQUIRES 4 bytes (0xFF, B, G, R).
print "Allocating..."
column = [0 for x in range(width)]
for x in range(width):
	column[x] = bytearray(height * 4)

# Convert entire RGB image into column-wise BGR bytearray list.
# The image-paint.py example proceeds in R/G/B order because it's counting
# on the library to do any necessary conversion.  Because we're preparing
# data directly for the strip, it's necessary to work in its native order.
print "Converting..."
for x in range(width):          # For each column of image...
	for y in range(height): # For each pixel in column...
		value             = pixels[x, y]    # Read pixel in image
		y4                = y * 4           # Position in raw buffer
		column[x][y4]     = 0xFF            # Pixel start marker
		column[x][y4 + rOffset] = gamma[value[0]] # Gamma-corrected R
		column[x][y4 + gOffset] = gamma[value[1]] # Gamma-corrected G
		column[x][y4 + bOffset] = gamma[value[2]] # Gamma-corrected B

print "Displaying..."
while True:                            # Loop forever

	for x in range(width):         # For each column of image...
		strip.show(column[x])  # Write raw data to strip
开发者ID:DDlabAU,项目名称:facadeSkilt,代码行数:32,代码来源:image-pov.py

示例10: Elevator

# 需要导入模块: from dotstar import Adafruit_DotStar [as 别名]
# 或者: from dotstar.Adafruit_DotStar import show [as 别名]
class Elevator(threading.Thread):
    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__()

    def onThread(self, function, *args, **kwargs):
        self.q.put((function, args, kwargs))

    def run(self):
        self.down()
        while True:
            if self.kill_event.is_set():
                self.close()
                return

            try:
                function, args, kwargs = self.q.get(timeout=self.timeout)
                function(*args, **kwargs)
            except Empty:
                pass

    def send_elevator_command(self, command):
        self.serial.flushInput()  # avoids that the input buffer overfloats
        self.serial.write(command)
        self.serial.flush()

    def up(self):
        self.status = "GOING_UP"
        self.send_elevator_command(ELEVATOR_UP)
        time.sleep(TIME_UP_S)
        self.status = "UP"
        self.set_lights(GREEN)

    def down(self):
        self.status = "GOING_DOWN"
        self.send_elevator_command(ELEVATOR_DOWN)
        self.set_lights(OFF)
        time.sleep(TIME_DOWN_S)
        self.status = "DOWN"
        time.sleep(TIME_TO_LEAVE_ELEVATOR_S)
        self.status = "FREE"
        
    def close(self):
        self.serial.close()

    def set_lights(self, color):
        for i in range(NUMPIXELS):
            self.strip.setPixelColor(i, color)
        if color == OFF:
            self.strip.setBrightness(0)
        else:
            self.strip.setBrightness(255)
        self.strip.show()
开发者ID:matthiasplappert,项目名称:lego-elevator,代码行数:72,代码来源:elevator.py

示例11: range

# 需要导入模块: from dotstar import Adafruit_DotStar [as 别名]
# 或者: from dotstar.Adafruit_DotStar import show [as 别名]
for i in range(256):
  gamma[i] = int(pow(float(i) / 255.0, 2.7) * 255.0 + 0.5)

def rgb_to_data(red, green, blue):
  data = [0xFF, 0x00, 0x00, 0x00]
  data[r_offs] = gamma[red]
  data[g_offs] = gamma[green]
  data[b_offs] = gamma[blue]

print "Displaying..."

solid_time = 1
fade_time = 0.05

print "Off"
strip.show(rgb_to_data(0,0,0))
time.sleep(solid_time)

print "Red"
strip.show(rgb_to_data(255,0,0))
time.sleep(solid_time)

print "Green"
strip.show(rgb_to_data(0,255,0))
time.sleep(solid_time)

print "Blue"
strip.show(rgb_to_data(0,255,0))
time.sleep(solid_time)

print "Off"
开发者ID:natmobile,项目名称:valo,代码行数:33,代码来源:single_pixel_fast.py

示例12: dither

# 需要导入模块: from dotstar import Adafruit_DotStar [as 别名]
# 或者: from dotstar.Adafruit_DotStar import show [as 别名]
			if dev is None: # Time-based

				startTime = time.time()
				while True:
					t1        = time.time()
					elapsed   = t1 - startTime
					if elapsed > duration: break
					# dither() function is passed a
					# destination buffer and a float
					# from 0.0 to 1.0 indicating which
					# column of the source image to
					# render.  Interpolation happens.
					lightpaint.dither(ledBuf,
					  elapsed / duration)
					strip.show(ledBuf)

			else: # Encoder-based

				mousepos = 0
				scale    = 0.01 / (speed_pixel + 1)
				while True:
					input = epoll.poll(-1) # Non-blocking
					for i in input: # For each pending...
						try:
							for event in dev.read():
								if(event.type == ecodes.EV_REL and
								   event.code == ecodes.REL_X):
									mousepos += event.value
						except:
							# If this occurs, usually power settings
开发者ID:adafruit,项目名称:DotStarPiPainter,代码行数:32,代码来源:DotStarPiPainter.py

示例13: povThread

# 需要导入模块: from dotstar import Adafruit_DotStar [as 别名]
# 或者: from dotstar.Adafruit_DotStar import show [as 别名]
class povThread(threading.Thread):
	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()

		####status data / show status function

	def off(self):
		self.running=False
		self.pause=False
		self.strip.show(self.empty_array)
		self.size=[0,0]
		self.pos=0

	def doPause(self):
		if self.running==True:
			if self.pause:
				self.pause=False
			else:
				self.pause=True

	def stop(self): # only to quit!! else: use self.off()
		self.off()
		self.freq.running=False
		self.active=False

#	def restart(self):
#		self.off()
#		self.running=True

	def showPOV(self, File=""):
		self.off()
		if File!="":
			self.povFile=File
		self.NEWrunning=True
		self.loading=True

	def run(self):

		while self.active:

			if self.NEWrunning==True:
				self.running=True
				self.NEWrunning=False

			if self.running == True:
				if self.povFile == "":
					print "Error: No pov-file specified!"
					self.off()
					self.loading=False

				else:
					f=open(self.povPath+self.povFile,'r')
					self.size=map(int,(f.readline().rstrip("\n")).split(','))
					width=self.size[0]

					print "\nLoading "+self.povPath+self.povFile + " into buffer; size: "+str(self.size[0])+"x"+str(self.size[1])
					lines = f.read().splitlines()
					array=[0 for i in range(width)]
					for i in range(width):
						array[i]=bytearray(60*4)
						j=0
						for LED in lines[i].split(','):
							array[i][j]=int(LED)
#.........这里部分代码省略.........
开发者ID:TobiBu,项目名称:POV,代码行数:103,代码来源:pov_control.py


注:本文中的dotstar.Adafruit_DotStar.show方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。