Пример #1
0
	def __init__(self):
		self.running = False

		# set the oled screen height
		self.screen_width = SCREEN_WIDTH
		self.screen_height = SCREEN_HEIGHT

		self.btn1Pin = LEFT_BTN_PIN
		self.btn2Pin = RIGHT_BTN_PIN
	 
	 	# configure interrups for buttons
	 	GPIO.setup(self.btn1Pin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
		GPIO.setup(self.btn2Pin, GPIO.IN, pull_up_down=GPIO.PUD_UP)  

		# configure screen
		spi_bus = 0
		spi_device = 0

		# Very important... This lets py-gaugette 'know' what pins to use in order to reset the display
		self.led = disp = Adafruit_SSD1306.SSD1306_128_64(rst=RST, dc=DC, spi=SPI.SpiDev(SPI_PORT, SPI_DEVICE, max_speed_hz=8000000)) # Change rows & cols values depending on your display dimensions.
		
		# Initialize library.
		self.led.begin()

		# Clear display.
		self.led.clear()
		self.led.display()


		# Create image buffer.
		# Make sure to create image with mode '1' for 1-bit color.
		self.image = Image.new('1', (self.screen_width, self.screen_height))

		# Load default font.
		self.font = ImageFont.load_default()

		# Create drawing object.
		self.draw = ImageDraw.Draw(self.image)

		# load the pump configuration from file
		self.pump_configuration = Bartender.readPumpConfiguration()
		for pump in self.pump_configuration.keys():
			GPIO.setup(self.pump_configuration[pump]["pin"], GPIO.OUT, initial=GPIO.HIGH)

		# setup pixels:
		self.numpixels = NUMBER_NEOPIXELS # Number of LEDs in strip

		# Here's how to control the strip from any two GPIO pins:
		datapin  = NEOPIXEL_DATA_PIN
		clockpin = NEOPIXEL_CLOCK_PIN
		self.strip = Adafruit_DotStar(self.numpixels, datapin, clockpin)
		self.strip.begin()           # Initialize pins for output
		self.strip.setBrightness(NEOPIXEL_BRIGHTNESS) # Limit brightness to ~1/4 duty cycle

		# turn everything off
		for i in range(0, self.numpixels):
			self.strip.setPixelColor(i, 0)
		self.strip.show() 

		print "Done initializing"
Пример #2
0
def main(render_sdl):
    if render_sdl:
        from sdl.driver import sdl_init
        from sdl.driver import sdl_draw
        window, renderer, pixels = sdl_init()

    else:
        from dotstar import Adafruit_DotStar
        strip = Adafruit_DotStar()
        strip.begin()

    t0 = time.time()
    i = 0

    while True:
        t = time.time() - t0
        i += 1
        try:
            importlib.reload(face)
            f = face.Face()
            f.render(t=t, i=i)
        except (ModuleNotFoundError):
            continue

        if render_sdl:
            print('rendering sdl')
            sdl_draw(pixels, window, f.grid)
        else:
            arr = face.to_arr()
            render_dotstar(strip, arr)
    def __init__(self):

        self.strip = Adafruit_DotStar(NUM_LEDS, 10, 11)
        self.strip.begin()
        self.stream = None

        self.time = 0
Пример #4
0
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
Пример #5
0
def cycle():
    strips = [
        Adafruit_DotStar(numpixels, datapin[0], clockpin[0]),
        Adafruit_DotStar(numpixels, datapin[1], clockpin[0]),
        Adafruit_DotStar(numpixels, datapin[2], clockpin[0])
    ]

    for strip in strips:
        strip.begin()

    color = 0x00FF00
    pos = (-1) * len(data[0])

    while True:
        for i, strip in enumerate(strips):
            strip.clear()

            for pixel in range(0, numpixels):
                for j, pixel in enumerate(data[i]):
                    if pixel == 1:
                        strip.setPixelColor(pos + j, color)

            strip.show()

        pos = pos + 1

        if pos == numpixels:
            pos = (-1) * len(data[0])

        time.sleep(0.10)
Пример #6
0
    def __init__(self):
        datapin = 10
        clockpin = 11

        if is_running_on_pi:
            self.strip = Adafruit_DotStar(0, datapin, clockpin, 18500000)
        else:
            self.strip = None
Пример #7
0
    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)
Пример #8
0
def init_arena():
    "Create the strip and buffer objects"
    global strip, arena, changed_panels
    global spi_clock, height, pwidth, width, npanels
    strip = Adafruit_DotStar(height*pwidth, spi_clock)
    strip.begin()
    #TODO For maximum speed, use a byte array of RGB values instead
    # (see `image-pov.py` in the Adafruit library for example code)
    arena = ["black"] * height * width
    changed_panels = [False] * npanels
Пример #9
0
 def __init__(self, datapin, clockpin, brightness):
     self.datapin = datapin
     self.clockpin = clockpin
     self.strip = Adafruit_DotStar(self.numpixels,
                                   self.datapin,
                                   self.clockpin,
                                   order='bgr')
     self.strip.begin()
     self.set_brightness(brightness)
     self.color = self.random_color()
Пример #10
0
 def open(self, num_pixels, order='rgb'):
     """
     Open the device
     :param num_pixels: Total number of pixels on the strip/string.
     :param order: The order of colors as expected by the strip/string.
     :return:
     """
     self._strip = Adafruit_DotStar(num_pixels, order=order.encode('utf-8'))
     # print self._strip
     self._numpixels = num_pixels
     return self._begin()
Пример #11
0
 def __init__(self):
     self.npixels = self.calc_npixels(self.sections_spec)
     self.strip = Adafruit_DotStar(self.npixels, self.datapin,
                                   self.clockpin)
     self.buffer = bytearray(self.npixels * 4)
     for i in range(0, self.npixels):
         self.buffer[i * 4] = 0xff
     self.sections = {}
     for spec in self.sections_spec:
         self.add_section(**spec)
     self.strip.begin()
Пример #12
0
class ImageLoader:
    def __init__(self):
        datapin = 10
        clockpin = 11

        if is_running_on_pi:
            self.strip = Adafruit_DotStar(0, datapin, clockpin, 18500000)
        else:
            self.strip = None

    def load_to_circular_buffer(self, path):
        if not is_running_on_pi:
            return

        img = Image.open(path).convert("RGB")
        pixels = img.load()
        width = img.size[0]
        height = img.size[1]

        circular_image = CircularImage(height, width)

        bytess = img.tobytes()

        for x in range(width):
            offset = x * 3
            multiplier = width * 3
            self.strip.prepareBuffer(circular_image.get_sample(x), bytess,
                                     offset, multiplier, False)

        for x in range(width):
            offset = x * 3
            multiplier = width * 3
            self.strip.prepareBuffer(circular_image.get_sample(x + width),
                                     bytess, offset, multiplier, True)

        circular_image.reverse()

        img.close()

        return circular_image

    @staticmethod
    def black():
        black = bytearray(144 * 4)
        for x in range(len(black)):
            if x % 4 == 0:
                black[x] = 0xFF
            else:
                black[x] = 0

        return black
Пример #13
0
	def __init__(self):
		self.running = False

		# set the oled screen height
		self.screen_width = SCREEN_WIDTH
		self.screen_height = SCREEN_HEIGHT

		self.btn1Pin = LEFT_BTN_PIN
		self.btn2Pin = RIGHT_BTN_PIN

	 	# configure interrups for buttons
	 	GPIO.setup(self.btn1Pin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
		GPIO.setup(self.btn2Pin, GPIO.IN, pull_up_down=GPIO.PUD_UP)

		# configure screen
		spi_bus = 0
		spi_device = 0
		gpio = gaugette.gpio.GPIO()
		spi = gaugette.spi.SPI(spi_bus, spi_device)

		# Very important... This lets py-gaugette 'know' what pins to use in order to reset the display
		self.led = gaugette.ssd1306.SSD1306(gpio, spi, reset_pin=OLED_RESET_PIN, dc_pin=OLED_DC_PIN, rows=self.screen_height, cols=self.screen_width) # Change rows & cols values depending on your display dimensions.
		self.led.begin()
		self.led.clear_display()
		self.led.display()
		self.led.invert_display()
		time.sleep(0.5)
		self.led.normal_display()
		time.sleep(0.5)

		# load the pump configuration from file
		self.pump_configuration = Bartender.readPumpConfiguration()
		for pump in self.pump_configuration.keys():
			GPIO.setup(self.pump_configuration[pump]["pin"], GPIO.OUT, initial=GPIO.HIGH)

		# setup pixels:
		self.numpixels = NUMBER_NEOPIXELS # Number of LEDs in strip

		# Here's how to control the strip from any two GPIO pins:
		datapin  = NEOPIXEL_DATA_PIN
		clockpin = NEOPIXEL_CLOCK_PIN
		self.strip = Adafruit_DotStar(self.numpixels, datapin, clockpin)
		self.strip.begin()           # Initialize pins for output
		self.strip.setBrightness(NEOPIXEL_BRIGHTNESS) # Limit brightness to ~1/4 duty cycle

		# turn everything off
		for i in range(0, self.numpixels):
			self.strip.setPixelColor(i, 0)
		self.strip.show()

		print "Done initializing"
Пример #14
0
class LedStrip:
    forward = True
    numpixels = 80
    head = 0
    tail = -10

    def random_color(self):
        return random.choice(colors)

    def __init__(self, datapin, clockpin):
        self.datapin = datapin
        self.clockpin = clockpin
        self.strip = Adafruit_DotStar(self.numpixels,
                                      self.datapin,
                                      self.clockpin,
                                      order='bgr')
        self.strip.begin()
        self.strip.setBrightness(255)
        self.color = self.random_color()

    def display_pixel(self, pos, color):
        self.strip.setPixelColor(pos, color)

    def render(self):
        self.strip.show()
Пример #15
0
class LedStrip:
    forward = True
    numpixels = 80
    head = 0
    tail = -10

    def random_color(self):
        return random.choice(color_library)

    def __init__(self, datapin, clockpin, brightness):
        self.datapin = datapin
        self.clockpin = clockpin
        self.strip = Adafruit_DotStar(self.numpixels,
                                      self.datapin,
                                      self.clockpin,
                                      order='bgr')
        self.strip.begin()
        self.set_brightness(brightness)
        self.color = self.random_color()

    def set_pixel(self, pos, color):
        r, g, b = toRGB(color)
        self.strip.setPixelColor(pos, gamma[r], gamma[g], gamma[b])

    def set_brightness(self, brightness):
        self.brightness = clamp(brightness, 0, 255)
        self.strip.setBrightness(self.brightness)

    def render(self):
        self.strip.show()
Пример #16
0
    def __init__(self):
        datapin    = 10
        clockpin   = 11

        self.column = None
        self.width = 0
        self.sequence = []
        self.cur_column = 0

        self.images_folder = ""

        if is_running_on_pi:
            self.strip = Adafruit_DotStar(0, datapin, clockpin, 18500000)            
        else:
            self.strip = None
Пример #17
0
 def __init__(self):
     numpixels = 128
     datapin = 10
     clockpin = 11
     self.strip = Adafruit_DotStar(numpixels, datapin, clockpin, 1000000)
     self.strip.begin()
     self.strip.setBrightness(64)
     SnipsMatrix.state_hotword = AnimationImage('hotword', self.strip)
     SnipsMatrix.state_time = AnimationTime(self.strip)
     SnipsMatrix.state_rotate = AnimationRotate(self.strip, 0)
     SnipsMatrix.state_weather = AnimationWeather(self.strip)
     SnipsMatrix.custom_anim = SnipsMatrix.load_custom_animation(self.strip)
     SnipsMatrix.queue.put(snipsMatrixAction.Hotword())
     SnipsMatrix.queue.put(snipsMatrixAction.Clear(
         DisplayPriority.hardware))
     t = threading.Thread(target=SnipsMatrix.worker, args=())
     t.start()
Пример #18
0
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\
Пример #19
0
    def __init__(self):
        datapin = 10
        clockpin = 11

        self.column = None
        self.width = 0
        self.sequence = []
        self.cur_column = 0

        self.images_folder = ""

        self.next_buffer_index = 0
        self.last_push = 0
        self.image_start_time = 0

        if is_running_on_pi:
            self.strip = Adafruit_DotStar(0, datapin, clockpin, 18500000)
        else:
            self.strip = None
Пример #20
0
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\
Пример #21
0
    def __init__(self):
        datapin = 10
        clockpin = 11

        self.buffer = bytearray(STRIP_LENGTH * 4)
        self.buffer_clear = bytearray(STRIP_LENGTH * 4)
        self.color_hsv = [0, 1, 0.7]
        self.start_time = time.time()

        self.cur_trail = 0

        for i in range(0, len(self.buffer_clear), 4):
            self.buffer_clear[i] = 0xFF
            self.buffer_clear[i + rOffset] = 0
            self.buffer_clear[i + gOffset] = 0
            self.buffer_clear[i + bOffset] = 0

        if is_running_on_pi:
            self.strip = Adafruit_DotStar(0, datapin, clockpin, 18500000)
        else:
            self.strip = None
Пример #22
0
    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()
Пример #23
0
class LEDStrip():
    datapin = 24
    clockpin = 25
    npixels = 0
    strip = None
    buffer = None
    sections_spec = []
    sections = None

    def __init__(self):
        self.npixels = self.calc_npixels(self.sections_spec)
        self.strip = Adafruit_DotStar(self.npixels, self.datapin,
                                      self.clockpin)
        self.buffer = bytearray(self.npixels * 4)
        for i in range(0, self.npixels):
            self.buffer[i * 4] = 0xff
        self.sections = {}
        for spec in self.sections_spec:
            self.add_section(**spec)
        self.strip.begin()

    def calc_npixels(self, sections):
        npixels = 0
        for spec in sections:
            if not "offset" in spec or spec["offset"] is None:
                spec["offset"] = npixels
            npixels = max(npixels, spec["offset"] + spec["length"])
        return npixels

    def add_section(self,
                    name=None,
                    offset=None,
                    length=0,
                    direction=1,
                    voffset=0,
                    vmul=1):
        self.sections[name] = LEDStripSection(self, offset, length, direction,
                                              voffset, vmul)
Пример #24
0
class PhysicalStrip:
    def __init__(self, numpixels):
        self._strip = Adafruit_DotStar(numpixels)
        self._strip.begin()

    def setPixelColor(self, i, color):
        self._strip.setPixelColor(i, color)

    def show(self):
        self._strip.show()
Пример #25
0
    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__()
Пример #26
0
	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()
Пример #27
0
#print("Cur Vol: %s " % current_volume)
#m.setvolume(100) # Set the volume to 70%.
#current_volume = m.getvolume() # Get the current Volume
#print("Cur Vol: %s " % current_volume)

numpixels = 120  # Number of LEDs in strip
# Here's how to control the strip from any two GPIO pins:
datapin = 23
clockpin = 24
defaultColor = 0x000099
defaultBright = 128
flashColor = 0xFFFFFF
flashBright = 128
lasthb = 0
hbinterval = 30
strip = Adafruit_DotStar(numpixels, datapin, clockpin)
strip.setBrightness(defaultBright)
strip.begin()  # Initialize pins for output

hi_thres = 50
low_thres = 40
beat = False


def main():
    global strip
    global beat
    global lasthb
    global hbinterval

    logevent("startup", "startup", "Just started and ready to run")
Пример #28
0
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:
Пример #29
0
            time.sleep(2)


#################
##Dotstar part###   <---put in main function?
#################

import time
from dotstar import Adafruit_DotStar

numpixels = 72  # 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(32)  # Limit brightness to ~1/4 duty cycle

#turn all black
offspot = 1
offcolor = 0x000000
while offspot >= 1:
    strip.setPixelColor(offspot, offcolor)
    offspot += 1
    if offspot == 72:
        break

jupspot = 36  #jupiter position
iospot = 1  #Io position ------------->trying for just one moon
Пример #30
0
import os
import serial
import random
import png
import struct
from time import sleep, time
from struct import pack, unpack
from dotstar import Adafruit_DotStar

numpixels = 144
gamma_value = 1.1

gamma = bytearray(256)
for i in range(256):
    gamma[i] = int(pow(float(i) / 255.0, gamma_value) * 255.0 + 0.5)

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

strip.begin()           # Initialize pins for output
strip.setBrightness(128) # Limit brightness to ~1/4 duty cycle

for row in xrange(144):
    strip.setPixelColor(row, 0)
strip.show()

# FF FF F0

for row in xrange(50):
    strip.setPixelColor(row, 0xaaaaa0)
strip.show()
Пример #31
0
def lightshow():
    numpixels = 72  # 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(128)  # Limit brightness to ~1/4 duty cycle

    #First, turn all black
    offspot = 1
    offcolor = 0x000000
    while offspot >= 1:
        strip.setPixelColor(offspot, offcolor)
        offspot += 1
        if offspot == 72:
            break

    #set initial spots and colors of Jupiter and moons

    jupspot = 36  #jupiter position
    jupcolor = 0xFF8801  #jupiter color

    iospot = iopos  #Io position
    iocolor = 0x9932cc  #Io color

    eurspot = eurpos  #Europa position
    eurcolor = 0x9932cc  #Europa color

    ganspot = ganpos  #Ganymede position
    gancolor = 0x9932cc  #Ganymede color

    calspot = calpos  #Calisto position
    calcolor = 0x9932cc  #Calisto color

    lastcolor = 0x000000
    lastiospot = (iospot - 1)

    gang = [iospot, eurspot, ganspot,
            calspot]  #list of the four moon positions

    while True:  # Loop forever

        strip.setBrightness(128)  # Limit brightness
        strip.setPixelColor(jupspot, jupcolor)  # Turn on jupiter to orange
        strip.setPixelColor(gang, 0)  #Turn off last plots
        gang[:] = [x + 1 for x in a]  # +=1 for each member of gang
        strip.setPixelColor(gang, iocolor)  # Turn all moons to blue
        strip.show()  # Refresh strip
        time.sleep(1.0 / 5)
        if t == now:
            strip.setBrightness(128)  #max brightness
            time.sleep(3)
        if (iospot >= numpixels):
            iospot = 0
        if (lastiospot >= numpixels):
            lastiospot = 0
# 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.
Пример #33
0
# 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':
Пример #34
0
#!/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
Пример #35
0
LED_COUNT = 7
API_TIMER = 60 * 10 # seconds
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)
Пример #36
0
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()
Пример #37
0
from dotstar import Adafruit_DotStar
from time import sleep

def go(colour, pause=0):
    for led in range(NUM_LEDS):
        print(led)
        r, g, b = colour
        strip.setPixelColor(led, r, g, b)
        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:
Пример #38
0
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()
Пример #39
0
#!/usr/bin/python

# Test the power supply capability to continuously drive all-on full white.
# 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,
Пример #40
0
#######Going for all 4 moons######


import ephem
import time
from dotstar import Adafruit_DotStar

#INITIALIZE AND CLEAR DOTSTAR

numpixels = 72                  # 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(8)         # Limit brightness to ~1/4 duty cycle

#turn all leds to black (off)
offspot = 1
offcolor = 0x000000
nump = 73
while offspot < nump:
        strip.setPixelColor(offspot, offcolor)
        offspot += 1
        strip.show()

#PYEPHEM PART--GET MOON SPOTS
Пример #41
0
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;
Пример #42
0
# 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 = 59 # Number of LEDs in strip

# Here's how to control the strip from any two GPIO pins:
datapin   = 20
clockpin  = 21
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(255) # 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.
Пример #43
0
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
Пример #44
0
#!/usr/bin/env python
import sys
import os
from dotstar import Adafruit_DotStar

numpixels = 144 # Number of LEDs in strip

def clear(strip):
    for row in xrange(numpixels):
        strip.setPixelColor(row, 0)

    strip.show();

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

strip.begin()           
clear(strip)
Пример #45
0
#!/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()
Пример #46
0
#!/usr/bin/python

import time
import math
import array
from dotstar import Adafruit_DotStar

numpixels = 72 # Number of LEDs in strip
fps = 8	# Nominal target Frames Per Second
# For POV aaplications, need 500+ FPS to get squarish pixels
#fps = 1024	# Nominal target Frames Per Second

strip   = Adafruit_DotStar(numpixels)           # Use SPI (pins 10=MOSI, 11=SCLK)

strip.begin()           # Initialize pins for output
strip.setBrightness(32) # Limit brightness to ~1/4 duty cycle

# 3-color totalistic cellular automaton
# colors are 0, 1, 2 (we usually show 0 as black)
colors = (0x000000, 0xFF0000, 0x007F7F)
ca = [0,1,2,1,0,0,1]	# code 777 CA
# see http://mathworld.wolfram.com/TotalisticCellularAutomaton.html

# Initialize CA, for now with 1 pixel
cells = array.array('B',(0,)*numpixels)
cells[int(numpixels/2)] = 2
sum = array.array('B',(0,)*numpixels)

while True:                              # Loop forever

	# Set strip colors and display them
Пример #47
0
#!/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)
Пример #48
0
# 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.
Пример #49
0
# 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).
uniqueSound = pygame.mixer.Sound("testSound.wav")
uniqueSound.set_volume(0)
uniqueSound.play(-1)

pygame.mixer.music.load("testSound.wav")
pygame.mixer.music.set_volume(0)
#pygame.mixer.music.play(-1)

totalPixels = 150  # Number of LEDs in Locker
pixel = 0

# Control Pins for the Raspberry Pi to the Dot Star strip
datapin = 23
clockpin = 24
# strip	  = Adafruit_DotStar(totalPixels, datapin, clockpin)
strip = Adafruit_DotStar(totalPixels, 100000)

strip.begin()  # Initialize pins for output
strip.setBrightness(254)  # Limit brightness to ~1/4 duty cycle

color = 0  # Global Color Value
prevColor = 0


class ColumnOSCThread(threading.Thread):
    def __init__(self, threadID, name):
        threading.Thread.__init__(self)
        self.threadID = threadID
        self.name = name

    def run(self):
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
# 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 = 30  # 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 = 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(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.
#!/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
    nearest = add(nearest, start)
    #    return (dist, nearest)
    return (dist)


# ----------------------------------------------------------

numpixels = 3 * 300 + 255 + 256  # Number of LEDs in strip + disk + square
#for i in range( numpixels ):
#    pixels.append( 0 )

maxLEDintensity = 64
mindist = 0.5  # Min distance for LED relative to line function that is ysed to set intensity 0.1 to 1 is reasonable

if flagPi:
    strip = Adafruit_DotStar(numpixels, 4000000)  # 4 MHz is more reliable
    strip.begin()  # Initialize pins for output
    strip.setBrightness(maxLEDintensity)  # Limit brightness to ~1/4 duty cycle

# Set up xy positions of each point
matrixLEDxy = []
matrixLEDintensity = []
matrixLEDcurrent = []

ll = [
    -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5,
    5.5, 6.5, 7.5
]
for i in range(16):
    for j in range(16):
        matrixLEDintensity.append(0)
Пример #55
0
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()
Пример #56
0
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 = "******"
dpass = "******"
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)
Пример #57
0
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
Пример #58
0
def strandtest():
    #!/usr/bin/python

    # 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 = 72 # 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)

    # Alternate ways of declaring strip:
    #  Adafruit_DotStar(npix, dat, clk, 1000000) # Bitbang @ ~1 MHz
    #  Adafruit_DotStar(npix)                    # Use SPI (pins 10=MOSI, 11=SCLK)
    #  Adafruit_DotStar(npix, 32000000)          # SPI @ ~32 MHz
    #  Adafruit_DotStar()                        # SPI, No pixel buffer
    #  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  = -10             # Index of last 'off' pixel
    color = 0xFF0000        # 'On' color (starts red)

    stranditer = 4
    strandnum = 0
    while strandnum <= stranditer:                              # 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
        strandnum += 1
Пример #59
0
#!/usr/bin/python

import time
from dotstar import Adafruit_DotStar

data_pin   = 23
clock_pin  = 24
strip      = Adafruit_DotStar(0, data_pin, clock_pin)

# Could be BRG or GBR. Figure out later.
# byte 0 is always 0xFF
# Here's the offsets for current (2015+) strips:
rOffset = 2
gOffset = 3
bOffset = 1

# Initialize pins for output
strip.begin()

# 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)

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..."