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


Python Adafruit_DotStar.setBrightness方法代码示例

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


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

示例1: init_strip

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

示例2: main

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

示例3: rgbStrip

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

示例4: __init__

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

示例5: rgbStripTest

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

示例6: Adafruit_DotStar

# 需要导入模块: from dotstar import Adafruit_DotStar [as 别名]
# 或者: from dotstar.Adafruit_DotStar import setBrightness [as 别名]
import time
from dotstar import Adafruit_DotStar
import MySQLdb
import colorsys

numpixels = 5 # Number of LEDs in strip

# 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
strip.setBrightness(64) # Limit brightness to ~1/4 duty cycle

dhost = "localhost"
duser = "root"
dpass = "bj1996BJ"
database = "home"
db = MySQLdb.connect(dhost,duser,dpass,database)

def scale(value, leftMin, leftMax, rightMin, rightMax):
    # Figure out how 'wide' each range is
    leftSpan = leftMax - leftMin
    rightSpan = rightMax - rightMin

    # Convert the left range into a 0-1 range (float)
    valueScaled = float(value - leftMin) / float(leftSpan)

    # Convert the 0-1 range into a value in the right range.
    return rightMin + (valueScaled * rightSpan)
开发者ID:Coolbots7,项目名称:CB_SmartHouse,代码行数:33,代码来源:caseLeds.py

示例7: main

# 需要导入模块: from dotstar import Adafruit_DotStar [as 别名]
# 或者: from dotstar.Adafruit_DotStar import setBrightness [as 别名]
def main(argv):
    global MODE
    global INPUT
    global p
    MODE = sys.argv[1]  # debug / pi
    INPUT = sys.argv[2] # camera / image / video
    p = ThreadPool(4)

    # MODE SETUP FOR LEDs or Display
    if MODE == 'debug':
        print('Running in Debug mode')
        cv2.namedWindow('preview')
        strip = True

    # If you're running on the PI, you want to setup the LED strip
    if MODE == 'pi':
        from dotstar import Adafruit_DotStar
        strip = Adafruit_DotStar(HEIGHT*WIDTH + OFFSET, DATAPIN, CLOCKPIN)
        strip.begin()

        # Lower power consumption, but makes it flicker.
        strip.setBrightness(LED_GLOBAL_BRIGHTNESS)

    bitmap = initialize_empty_bitmap()
    render_bitmap(bitmap, strip)

    # INPUT SELECTION SETUP
    # If you're using a USB camera for input
    # TODO: Allow for arg use for different cameras
    if INPUT == 'camera':
        if MODE == 'debug':
            cv2.namedWindow('cameraPreview', cv2.WINDOW_NORMAL)
        vc = cv2.VideoCapture(0)
        if vc.isOpened():
            # vc.set(15, -10)
            vc.set(3,200) # These aren't accurate, but help
            vc.set(4,100)
            rval, frame = vc.read()
        else:
            rval = False

        while rval:
            rval, frame = vc.read()
            # if MODE == 'debug':
                # cv2.imshow('cameraPreview', frame)
            start = time.time()
            flow(frame, bitmap, strip)
            key = cv2.waitKey(15)
            if key == 27: # exit on ESC
                break
            end = time.time()
            print(end - start)

    # If you're using a static image for debugging
    if INPUT == 'image':
        if len(sys.argv) == 4:
            frame = cv2.imread(sys.argv[3])
        else:
            frame = cv2.imread('bars.jpg')
        rval = True

        # while True:
        # For 1000 frames
        start = time.time()
        while True:
            flow(frame, bitmap, strip)
            key = cv2.waitKey(15)
            if key == 27: # exit on ESC
                break
        end = time.time()
        fps = 1000 / (end - start)
        print('fps:', fps)



    # If you're using a pre-recorded video for debugging set it here
    if INPUT == 'video':
        cv2.namedWindow('videoPreview', cv2.WINDOW_NORMAL)
        vc = cv2.VideoCapture('WaveCanon2.mp4')
        if vc.isOpened():
            rval, frame = vc.read()
        else:
            rval = False

        while rval:
            rval, frame = vc.read()
            frame = shrink(frame) # 1080p video too big coming in
            cv2.imshow('videoPreview', frame)
            flow(frame, bitmap, strip)
            key = cv2.waitKey(15)
            if key == 27: # exit on ESC
                break

        return False
开发者ID:clearf,项目名称:lights,代码行数:96,代码来源:lights.py

示例8: Elevator

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

示例9: Adafruit_DotStar

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

f.close()
开发者ID:HowardALandman,项目名称:HForce,代码行数:32,代码来源:power_test.py

示例10: sleep

# 需要导入模块: from dotstar import Adafruit_DotStar [as 别名]
# 或者: from dotstar.Adafruit_DotStar import setBrightness [as 别名]
        strip.show()
        sleep(pause)

NUM_LEDS = 100

DATAPIN = 15
CLOCKPIN = 14
strip = Adafruit_DotStar(NUM_LEDS, DATAPIN, CLOCKPIN)

RED = (255, 0, 0)
GREEN = (0, 255, 0)
OFF = (0, 0, 0)

strip.begin()

brightness = 255
strip.setBrightness(brightness)
go(OFF)
print("done")


def main():
    while True:
        print("green")
        go(GREEN, 0.1)
        print("red")
        go(RED, 0.1)

if __name__ == '__main__':
    main()
开发者ID:bennuttall,项目名称:garden-exhibition,代码行数:32,代码来源:red_green.py

示例11: Color

# 需要导入模块: from dotstar import Adafruit_DotStar [as 别名]
# 或者: from dotstar.Adafruit_DotStar import setBrightness [as 别名]
CONNECTIVITY_TIMER = 15 # seconds
PRECIP_PROBABILITY = 0.2
GLOBAL_BRIGHTNESS = 0.25

# color settings
clear_day = rain = Color(15, 50, 255)
clear_night = Color(0, 0, 255, 0.1)
fog = cloudy = Color(255, 255, 255, 0.4)
snow = Color(255, 255, 255)

# setup LEDs
datapin   = 10
clockpin  = 11
strip     = Adafruit_DotStar(LED_COUNT, datapin, clockpin)
strip.begin()           # Initialize pins for output
strip.setBrightness(int(GLOBAL_BRIGHTNESS * 255.0)) # Limit brightness to ~1/4 duty cycle

precipHours = []
loopCount = 0
thread = None
connectThread = None
data = None
logger = None
active = False
isInit = False


def init():
  # logger = firelog(data['product_name'], data['guid'], data)
  internetOn(True)
开发者ID:nick-jonas,项目名称:umbrellastand,代码行数:32,代码来源:weather.py

示例12: Adafruit_DotStar

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

# Note that the actual period will be the specified period PLUS compute time.
开发者ID:HowardALandman,项目名称:HForce,代码行数:32,代码来源:strobe.py

示例13: main

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

示例14: Adafruit_DotStar

# 需要导入模块: from dotstar import Adafruit_DotStar [as 别名]
# 或者: from dotstar.Adafruit_DotStar import setBrightness [as 别名]
# Here's how to control the strip from any two GPIO pins:
datapin   = 2 #BCM - Orange
clockpin  = 3 #BCM - Gul
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
strip.setBrightness(255)

# 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  = -32             # 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 / 50)             # Pause 20 milliseconds (~50 fps)
    time.sleep(1.0 / 75)
开发者ID:DDlabAU,项目名称:facadeSkilt,代码行数:33,代码来源:strandtest.py

示例15: sleep

# 需要导入模块: from dotstar import Adafruit_DotStar [as 别名]
# 或者: from dotstar.Adafruit_DotStar import setBrightness [as 别名]
                        color = (red << 16 | green << 8 | blue)
                        strip.setPixelColor(numpixels - row, color)

                    strip.show()
                    sleep(.0004)

                clear(strip)
                if time() > timeout:
                    break

                sleep(.05)


if len(sys.argv) < 2:
    print "Usage: %s: <png file> [png file] ..." % sysargv[0]
    sys.exit(-1)


strip = Adafruit_DotStar(numpixels, order='bgr')

strip.begin()           
strip.setBrightness(70) 
startup(strip)

images = load_files(sys.argv[1:])
try:
    main_loop(strip, images)
except KeyboardInterrupt:
    clear(strip)
    sys.exit(0)
开发者ID:mayhem,项目名称:ledstick,代码行数:32,代码来源:ledstick.py


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