示例#1
0
def config_fn(data, t):
    print("Config: %s" % hexlify(data))

    d = {}
    d["numleds"] = (data[0] << 8) + data[1]
    init_cmd = data[2:]

    fout = open("settings.cfg", 'wb')
    fout.write(json.dumps(d) + "\n")
    fout.write(init_cmd)
    fout.close()

    # Pause the animator and update the strip with the new number of LEDs.
    t.pause()
    t.strip = neopixel.Adafruit_NeoPixel(
        d["numleds"],
        NEOPIXEL_PIN,
        NEOPIXEL_HZ,
        5,
        False,
        strip_type=neopixel.ws.WS2811_STRIP_GRB)
    t.strip.setBrightness(MAX_BRIGHTNESS)
    t.strip.begin()

    # Call the new default animation fn (which will resume the animator if it wishes)
    cmd = init_cmd[0]
    n = (init_cmd[1] << 8) + init_cmd[2]

    assert len(init_cmd[3:]
               ) == n, "Incorrectly sized data packet. Expected %x, got %x" % (
                   n, len(init_cmd[3:]))

    commands[cmd](init_cmd[3:], t)
示例#2
0
 def init(cls):
     # Create NeoPixel object with appropriate configuration.
     cls.strip = neopixel.Adafruit_NeoPixel(cls.LED_COUNT, cls.LED_PIN,
                                            cls.LED_FREQ_HZ, cls.LED_DMA,
                                            cls.LED_INVERT)
     # Intialize the library (must be called once before other functions).
     cls.strip.begin()
示例#3
0
文件: saber.py 项目: dash-dash/saber
 def __init__(self, max_brightness=255):
     self.strand_lights = sum(config.SIDES)
     self.strand = neo.Adafruit_NeoPixel(self.strand_lights, config.LED_PIN,
                                         config.LED_FREQ, config.LED_DMA,
                                         config.LED_INVERT, max_brightness,
                                         config.LED_CHANNEL)
     self.strand.begin()
示例#4
0
文件: devices.py 项目: vageesh79/Vela
 def __init__(self,
              n_pixels,
              pin=18,
              invert_logic=False,
              freq=800000,
              dma=5):
     """Creates a Raspberry Pi output device
     Parameters
     ----------
     n_pixels: int
         Number of LED strip pixels
     pin: int, optional
         GPIO pin used to drive the LED strip (must be a PWM pin).
         Pin 18 can be used on the Raspberry Pi 2.
     invert_logic: bool, optional
         Whether or not to invert the driving logic.
         Set this to True if you are using an inverting logic level
         converter, otherwise set to False.
     freq: int, optional
         LED strip protocol frequency (Hz). For ws2812 this is 800000.
     dma: int, optional
         DMA (direct memory access) channel used to drive PWM signals.
         If you aren't sure, try 5.
     """
     try:
         import neopixel
     except ImportError as e:
         url = 'learn.adafruit.com/neopixels-on-raspberry-pi/software'
         print('Could not import the neopixel library')
         print('For installation instructions, see {}'.format(url))
         raise e
     self.strip = neopixel.Adafruit_NeoPixel(n_pixels, pin, freq, dma,
                                             invert_logic, 255)
     self.strip.begin()
示例#5
0
def init():
    from main import LedArray
    LED_COUNT = 37 * 4  # Number of LED pixels.
    LED_PIN = 18  # GPIO pin connected to the pixels (18 uses PWM!).
    # LED_PIN        = 10      # GPIO pin connected to the pixels (10 uses SPI /dev/spidev0.0).
    LED_FREQ_HZ = 800000  # LED signal frequency in hertz (usually 800khz)
    LED_DMA = 11  # DMA channel to use for generating signal (try 10)
    LED_BRIGHTNESS = 50  # Set to 0 for darkest and 255 for brightest
    LED_INVERT = False  # True to invert the signal (when using NPN transistor level shift)
    LED_CHANNEL = 0  # set to '1' for GPIOs 13, 19, 41, 45 or 53
    strip = neopixel.Adafruit_NeoPixel(LED_COUNT,
                                       LED_PIN,
                                       LED_FREQ_HZ,
                                       LED_DMA,
                                       LED_INVERT,
                                       LED_BRIGHTNESS,
                                       LED_CHANNEL,
                                       strip_type=neopixel.ws.WS2811_STRIP_GRB)

    # Intialize the library (must be called once before other functions).
    strip.begin()
    set_all(strip, neopixel.Color(0, 0, 0))

    here = (48.224708, 16.438082)  # lat long

    leds = LedArray([49.0, 32.0, 16.5, 0.0], [18, 12, 6, 1], [
        -np.pi / 2 + np.deg2rad(10), -np.pi / 2, -np.pi / 2 - np.deg2rad(30), 0
    ], [1, -1, -1, 1], 200, *here, [500, 1000, 2500])

    return strip, leds
def InitStrip():
	global strip 
	
	# Create NeoPixel object with appropriate configuration.
	strip = neopixel.Adafruit_NeoPixel(LED_COUNT, LED_PIN, LED_FREQ_HZ, LED_DMA, LED_INVERT, LED_BRIGHTNESS)

	# Intialize the library (must be called once before other functions).
	strip.begin()
示例#7
0
文件: cubert.py 项目: furbrain/cubert
    def __init__(self):

        # Create NeoPixel object with appropriate configuration.
        self.strip = neopixel.Adafruit_NeoPixel(self.LED_COUNT, self.LED_PIN,
                                                self.LED_FREQ_HZ, self.LED_DMA,
                                                self.LED_INVERT)
        # Intialize the library (must be called once before other functions).
        self.strip.begin()
示例#8
0
def led_strip_from_constants():
    return neopixel.Adafruit_NeoPixel(LED_COUNT,
                                      LED_PIN,
                                      LED_FREQ_HZ,
                                      LED_DMA,
                                      LED_INVERT,
                                      LED_BRIGHTNESS,
                                      LED_CHANNEL,
                                      strip_type=neopixel.ws.WS2811_STRIP_GRB)
def main():
    file_name = sys.argv[1] if len(sys.argv) == 2 else 'config.json'

    with open(file_name, 'rb') as config_file:
        config = json.load(config_file)

    tide_station = config['tide_station']
    tide_time_offset_low = config['tide_time_offset']['low']
    tide_time_offset_high = config['tide_time_offset']['high']
    tide_level_offset_low = config['tide_level_offset']['low']
    tide_level_offset_high = config['tide_level_offset']['high']
    tide_request_window_back = config['tide_request_window']['back']
    tide_request_window_forward = config['tide_request_window']['forward']
    tide_renew_threshold = config['tide_renew_threshold']

    yellow_threshold = config['water_level_thresholds']['yellow']
    green_threshold = config['water_level_thresholds']['green']
    water_level_minutes = datetime.timedelta(
        minutes=config['water_level_minutes'])

    init_logger(config['log_file_name'])

    strip = neopixel.Adafruit_NeoPixel(LED_COUNT, config['led_pin'],
                                       LED_FREQ_HZ, LED_DMA, LED_INVERT,
                                       config['led_brightness'], LED_CHANNEL,
                                       LED_STRIP)

    strip.begin()

    time_offset = predictions.AdditiveOffset(
        datetime.timedelta(minutes=tide_time_offset_low),
        datetime.timedelta(minutes=tide_time_offset_high))
    level_offset = predictions.MultiplicativeOffset(tide_level_offset_low,
                                                    tide_level_offset_high)
    tide_offset = predictions.TideOffset(time_offset, level_offset)
    query_range = (datetime.timedelta(days=tide_request_window_back),
                   datetime.timedelta(days=tide_request_window_forward))
    renew_threshold = datetime.timedelta(days=tide_renew_threshold)

    tt = task.TideTask(tide_station, tide_offset, query_range, renew_threshold)
    tt.start()

    while True:
        now = datetime.datetime.utcnow()
        later = now + water_level_minutes
        tide_now = tt.await_tide(now)
        tide_later = tt.await_tide(later)
        logger.info('tide now: {}'.format(tide_now))
        logger.info('tide later: {}'.format(tide_later))
        if tide_now.level >= green_threshold and tide_later.level >= green_threshold:
            render(strip, False, False, True)
        elif tide_now.level >= yellow_threshold and tide_later.level >= yellow_threshold:
            render(strip, False, True, False)
        else:
            render(strip, True, False, False)
        time.sleep(60)
示例#10
0
def start():
    global strip
    # Create NeoPixel object with appropriate configuration.
    strip = neopixel.Adafruit_NeoPixel(config.N_PIXELS, config.LED_PIN,
                                       config.LED_FREQ_HZ, config.LED_DMA,
                                       config.LED_INVERT,
                                       config.LED_BRIGHTNESS,
                                       config.LED_CHANNEL, config.LED_STRIP)
    # Intialize the library (must be called once before other functions).
    strip.begin()
示例#11
0
文件: screen.py 项目: LemaruX/pixelpi
	def __init__(self, width = 16, height = 16, led_pin = 18, led_freq_hz = 800000, led_dma = 5, led_invert = False, led_brightness = 200):
		super(Screen, self).__init__(width, height)
		import neopixel
		
		self.strip = neopixel.Adafruit_NeoPixel(width * height, led_pin, led_freq_hz, led_dma, led_invert, led_brightness, strip_type=528384)
		self.strip.begin()
		self.update_brightness()
		
		global instance
		instance = self	
示例#12
0
 def make_strip(self):
     return neopixel.Adafruit_NeoPixel(
         self.LED_COUNT,
         self.LED_PIN,
         self.LED_FREQ_HZ,
         self.LED_DMA,
         self.LED_INVERT,
         self.LED_BRIGHTNESS,
         self.LED_CHANNEL,
     )
示例#13
0
 def __init__(self, num_leds, led_pin, led_data_rate, led_dma_channel,
              led_pixel_order):
     self.leds = neopixel.Adafruit_NeoPixel(num_leds, led_pin,
                                            led_data_rate, led_dma_channel,
                                            False, 255)
     self.px_order = led_pixel_order
     self.leds.begin()
     for i in range(num_leds):
         self.leds.setPixelColor(i, neopixel.Color(0, 0, 0))
     self.leds.show()
示例#14
0
    def __init__(self):
        # LED strip configuration:
        LED_COUNT = 5  # Number of LED pixels.
        #LED_PIN        = 18      # GPIO pin connected to the pixels (18 uses PWM!).
        #LED_PIN        = 10      # GPIO pin connected to the pixels (10 uses SPI /dev/spidev0.0).
        LED_FREQ_HZ = 800000  # LED signal frequency in hertz (usually 800khz)
        LED_DMA = 10  # DMA channel to use for generating signal (try 10)
        LED_BRIGHTNESS = 80  # Set to 0 for darkest and 255 for brightest
        LED_INVERT = False  # True to invert the signal (when using NPN transistor level shift)
        LED_CHANNEL = 0  # set to '1' for GPIOs 13, 19, 41, 45 or 53
        confs = utils.getConfiguration(self.name)
        if confs != None:
            self.channel = confs['channel']
            if self.channel != 'None':
                self.channel = int(self.channel)
            else:
                self.channel = False
            print("FrontLED initialized - configuration found")
        else:
            self.channel = 18
            newConfs = [('channel', None)]
            utils.setConfiguration(self.name, newConfs)
            print("FrontLED initialized - Warning: new configuration")

        if self.channel != False:
            #from neopixel import *
            import neopixel
            # Create NeoPixel object with appropriate configuration.
            self.strip = neopixel.Adafruit_NeoPixel(LED_COUNT, self.channel,
                                                    LED_FREQ_HZ, LED_DMA,
                                                    LED_INVERT, LED_BRIGHTNESS,
                                                    LED_CHANNEL)
            # Intialize the library (must be called once before other functions).
            self.strip.begin()
            print("LED Strip  initialized")
        else:
            self.dimmer = ExecutePWM.ExecutePWM()
            confs = utils.getConfiguration(self.name)
            if confs != None:
                self.channel_0 = int(confs['channel_0'])
                self.channel_1 = int(confs['channel_1'])
                self.channel_2 = int(confs['channel_2'])
                self.channel_3 = int(confs['channel_3'])
                self.channel_4 = int(confs['channel_4'])
                print("Old IndicatorPanel initialized - configuration found")
            else:
                newConfs = [('channel_0', None), ('channel_1', None),
                            ('channel_2', None), ('channel_3', None),
                            ('channel_4', None)]
                utils.setConfiguration(self.name, newConfs)
                print(
                    "Old IndicatorPanel initialized - Warning: new configuration"
                )
 def __init__(self, **cnf):
     # Create NeoPixel object with appropriate configuration.
     count = cnf.get("count", self.LED_COUNT)
     pin = cnf.get("pin", self.LED_PIN)
     freq_hz = cnf.get("freq_hz", self.LED_FREQ_HZ)
     dma = cnf.get("dma", self.LED_DMA)
     invert = cnf.get("invert", self.LED_INVERT)
     brightness = cnf.get("brightness", self.LED_BRIGHTNESS)
     channel = cnf.get("channel", self.LED_CHANNEL)
     strip = cnf.get("strip", self.LED_STRIP)
     self.strip = np.Adafruit_NeoPixel(count, pin, freq_hz, dma, invert,
                                       brightness, channel, strip)
     # Intialize the library (must be called once before other functions).
     self.strip.begin()
示例#16
0
def main():
    strip = neopixel.Adafruit_NeoPixel(LED_COUNT, LED_PIN, LED_FREQ_HZ,
                                       LED_DMA, LED_INVERT, LED_BRIGHTENESS)
    strip.begin()

    while (True):
        rpm = adc.read_voltage(1)
        print(rpm)  # debug tensione
        if rpm > 1 and rpm < 2:
            for j in range(1):
                strip.setPixelColorRGB(j, 0, 255, 0)
                strip.setPixelColorRGB(LED_COUNT - j - 1, 0, 255, 0)
            for i in range(2, 15):
                strip.setPixelColorRGB(i, 0, 0, 0)
        if rpm > 2 and rpm < 3:
            for j in range(1, 2):
                strip.setPixelColorRGB(j, 0, 255, 0)
                strip.setPixelColorRGB(LED_COUNT - j - 1, 0, 255, 0)
            for x in range(2, 4):
                strip.setPixelColorRGB(x, 255, 0, 0)
                strip.setPixelColorRGB(LED_COUNT - x - 1, 255, 0, 0)
            for i in range(4, 12):
                strip.setPixelColorRGB(i, 0, 0, 0)
        if rpm > 3 and rpm < 4:
            for i in range(1, 2):
                strip.setPixelColorRGB(j, 0, 255, 0)
                strip.setPixelColorRGB(LED_COUNT - j - 1, 0, 255, 0)
            for x in range(2, 4):
                strip.setPixelColorRGB(x, 255, 0, 0)
                strip.setPixelColorRGB(LED_COUNT - x - 1, 255, 0, 0)
            for j in range(5, 6):
                strip.setPixelColorRGB(j, 0, 0, 255)
                strip.setPixelColorRGB(LED_COUNT - j - 1, 0, 0, 255)
            for i in range(7, 11):
                strip.setPixelColorRGB(i, 0, 0, 0)
        if rpm > 4 and rpm < 6:
            for i in range(1, 2):
                strip.setPixelColorRGB(i, 0, 255, 0)
                strip.setPixelColorRGB(LED_COUNT - i - 1, 0, 255, 0)
            for x in range(2, 4):
                strip.setPixelColorRGB(x, 255, 0, 0)
                strip.setPixelColorRGB(LED_COUNT - x - 1, 255, 0, 0)
            for j in range(5, 6):
                strip.setPixelColorRGB(j, 0, 0, 255)
                strip.setPixelColorRGB(LED_COUNT - j - 1, 0, 0, 255)
            for p in range(7, 8):
                strip.setPixelColorRGB(p, 0, 0, 255)
                strip.setPixelColorRGB(LED_COUNT - p - 1, 0, 0, 255)
        strip.show()
示例#17
0
    def __init__(self, brightness=150):
        # Pip install rpi_ws281x
        #
        # NB: Do this import inside the constructor so that only tests which
        # explicitly require instantiating the class will require the import
        # which is platform-dependent
        import neopixel

        super(KanoHatLeds, self).__init__()

        self._leds = neopixel.Adafruit_NeoPixel(KanoHatLeds.LED_COUNT,
                                                KanoHatLeds.LED_PIN,
                                                dma=10)

        self.set_brightness(brightness)
        self._leds.begin()
示例#18
0
    def __init__(self):
        self.current_color = None

        self.transition_from_color = None
        self.transition_to_color = None
        self.transition_alpha = 0

        self.current_animation = None

        self.strip = neopixel.Adafruit_NeoPixel(
            RgbLed.LED_COUNT, RgbLed.LED_PIN, RgbLed.LED_FREQ_HZ,
            RgbLed.LED_DMA, RgbLed.LED_INVERT, RgbLed.LED_BRIGHTNESS)
        self.strip.begin()

        # set default color
        self.set_color(color.red)
示例#19
0
def init(system, config):
    """
    bring the hardware online
    :param system (dict): global settings and handy objects
    :param config (dict): preferences in a global dictionary
    """

    # update system settings

    global _screenW
    global _screenH
    cfg = config['platform_cfg']['raspi']
    system["theme_path"] = cfg['themebasepath']
    _screenW = system["screen_width"] = cfg[
        'screen_width']  # this is specific to this hardware anyway
    _screenH = system["screen_height"] = cfg['screen_height']

    global _display
    _display = povserial.pov(cfg)

    # setup gpios
    gpio.setmode(gpio.BCM)
    # pin GPIO23 is connected to the sound relay
    gpio.setup(GPIO_RELAY, gpio.OUT, initial=gpio.LOW)

    # Create NeoPixel object with appropriate configuration.
    global _strip
    _strip = neopixel.Adafruit_NeoPixel(LED_COUNT, LED_PIN, LED_FREQ_HZ,
                                        LED_DMA, LED_INVERT, LED_BRIGHTNESS)
    _strip.begin()

    pygame.mixer.pre_init(frequency=41000, channels=1, buffer=4096 * 2)
    pygame.init()
    pygame.mixer.set_num_channels(16)

    if 'forceDisplayWindow' in system:  # for debugging
        pygame.display.set_mode((160, 180))

    displayOn(True)
    _display.secondsDisplay(False)
    _display.clear()

    __init_lut(system)
    system['canvas'] = fc.Canvas(w=_screenW, h=_screenH)

    print 'sys lamp: init done.'
示例#20
0
def start():
    if neopixel:
        app.strip = neopixel.Adafruit_NeoPixel(LED_COUNT, LED_PIN, LED_FREQ_HZ,
                                               LED_DMA, LED_INVERT,
                                               LED_BRIGHTNESS)
        app.strip.begin()
        clear_display(app.strip)

        #app.displayThread = DisplayJAnimThread(app.strip)
        app.displayThread = DisplayShowPlaylistThread(
            app.strip, 'playlists/imageloop.csv')
        app.displayThread.start()
    else:
        app.strip = None

    app.wlan0_ip = ipaddr.get_ip('wlan0')
    app.run(host='0.0.0.0', port=80, debug=True)
示例#21
0
 def setup_strip(self):
     brightness = self.strip_conf.get("brightness")
     if (0 < brightness and brightness < 1):
         brightness = int(brightness * 255)
     strip_type = self.strip_conf.get("strip")
     if (strip_type == "ws281x"):
         strip_type = neopixel.ws.WS2811_STRIP_GRB
     strip = neopixel.Adafruit_NeoPixel(self.strip_conf.get("count"),
                                        self.strip_conf.get("pin"),
                                        self.strip_conf.get("freq"),
                                        self.strip_conf.get("DMA"),
                                        self.strip_conf.get("invert"),
                                        brightness,
                                        self.strip_conf.get("channel"),
                                        strip_type)
     strip.begin()
     return strip
    def __init__(self, strip_size, strip_pin, strip_brightness=255):

        import neopixel

        self.strip_size = strip_size
        self.strip_pin = strip_pin
        self.strip_brightness = strip_brightness

        self.strip_type = getattr(
            neopixel.ws,
            '%s_STRIP_%s' % (self.strip_type_name, self.strip_type_order))

        self.strip = neopixel.Adafruit_NeoPixel(
            self.strip_size, self.strip_pin, self.strip_freq_hz,
            self.strip_dma, self.strip_invert, self.strip_brightness,
            self.strip_channel, self.strip_type)

        self.strip.begin()
示例#23
0
	def __init__(self,pin,default_anim,brightness=255):

		Thread.__init__(self)

		self._strip = neopixel.Adafruit_NeoPixel(self.LED_COUNT, pin, self.LED_FREQ_HZ, self.LED_DMA, self.LED_INVERT, brightness, self.LED_CHANNEL)

		self._animation = default_anim
		self._new_animation_event = Event()
		self._running = True

		self._pause_event = Event()
		self._pause_event.set()

		self._locker = RLock()

		# dunno better
		self._bottle_fill_level = 0 # liquid szint
		self._wipe_pointer = 0 # meddig lett letorolve
示例#24
0
 def setup_strip(self):
     import neopixel
     brightness = self.strip_conf.get("brightness")
     if 0 < brightness < 1:
         brightness = int(brightness * 255)
     strip_type = self.strip_conf.get("strip")
     if strip_type == "ws281x":
         # must have installed rpi_ws281x
         strip_type = neopixel.ws.WS2811_STRIP_GRB
     strip = neopixel.Adafruit_NeoPixel(self.strip_conf.get("count"),
                                        self.strip_conf.get("pin"),
                                        self.strip_conf.get("freq"),
                                        self.strip_conf.get("DMA"),
                                        self.strip_conf.get("invert"),
                                        brightness,
                                        self.strip_conf.get("channel"),
                                        strip_type)
     strip.begin()
     return strip
示例#25
0
    def __init__(self):
        self.strip_handler = neopixel.Adafruit_NeoPixel(
            led_data.LED_COUNT, led_data.LED_PIN, led_data.LED_FREQ_HZ,
            led_data.LED_DMA, led_data.LED_INVERT, led_data.LED_BRIGHTNESS,
            led_data.LED_CHANNEL, led_data.LED_STRIP)
        self.strip_handler.begin()
        self.strip_handler.setBrightness(50)
        logging.info('LED strip started')

        msg = 'Neo pixel LEDs: {}, X: {}, Y: {}, font X: {}, font Y: {}.'
        logging.debug(
            msg.format(led_data.LED_COUNT, led_data.LED_COUNT_X,
                       led_data.LED_COUNT_Y,
                       selected_font[font_data.FONT_TUPLE_X],
                       selected_font[font_data.FONT_TUPLE_Y]))
        self.act_time = 0
        self.old_time = 0
        self.message = ''
        self.i = font_data.FONT_OFFSET_X
        self.red = 100
        self.blue = 0
        self.green = 0
        self.color = neopixel.Color(50, 50, 0)
示例#26
0
def main(args):

	global sock
	global strip


	sock = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
	sock.bind(("0.0.0.0",UDPport))

	# initialize the strip.
	print "... create ..."
	strip = neopixel.Adafruit_NeoPixel(LED_COUNT, LED_PIN, LED_FREQ_HZ, LED_DMA, LED_INVERT, LED_BRIGHTNESS, LED_CHANNEL)
	# Intialize the library (must be called once before other functions).
	print "... done ... start ..."
	strip.begin()
	print "... done ..."

	load_default_gammacurves()

	print "start loop, listen-port %u" % UDPport

	data = sock.recv(10000)


	try:
		while(data):
			## #print "UDP data %s" % repr(data)[:55]
			proc_input(data)
			data = sock.recv(10000)
	except socket.timeout:
		sock.close()

	print "exiting..."
	time.sleep(0.25)

	return 0
示例#27
0
import sys

LED_COUNT = 5
LED_PIN = 18
LED_BRIGHTNESS = 255
LED_CHANNEL = 0


def SetColor(strip, num, color, milli_sec):
    for i in range(milli_sec):
        strip.setPixelColor(num, color)
        strip.show()
        time.sleep(0.001)


strip = neopixel.Adafruit_NeoPixel(LED_COUNT, LED_PIN, 800000, 10, False,
                                   LED_BRIGHTNESS, LED_CHANNEL, 1050624)
strip.begin()


def OneByOne():
    for i in range(LED_COUNT):
        if i % 3 == 1:
            for j in range(256):
                SetColor(strip, i, neopixel.Color(j, 0, 255 - j),
                         1)  #Blue ~ Red
            for j in range(256):
                SetColor(strip, i, neopixel.Color(255 - j, j, 0),
                         1)  #Red ~ Green
            for j in range(256):
                SetColor(strip, i, neopixel.Color(0, 255 - j, j),
                         1)  #Green ~ Blue
示例#28
0
            sleep(1)
    print("Found device {}, with IP address {}".format(config.settings["configuration"]["MAC_ADDR"], ip_addr))
    config.settings["configuration"]["UDP_IP"] = ip_addr

# ESP8266 uses WiFi communication
if config.settings["configuration"]["DEVICE"] == 'esp8266':
    import socket
    from subprocess import check_output
    from time import sleep
    _sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    _sock.settimeout(0.005)
# Raspberry Pi controls the LED strip directly
elif config.settings["configuration"]["DEVICE"] == 'pi':
    import neopixel
    strip = neopixel.Adafruit_NeoPixel(config.settings["configuration"]["N_PIXELS"], config.settings["configuration"]["LED_PIN"],
                                       config.settings["configuration"]["LED_FREQ_HZ"], config.settings["configuration"]["LED_DMA"],
                                       config.settings["configuration"]["LED_INVERT"], config.settings["configuration"]["BRIGHTNESS"])
    strip.begin()
elif config.settings["configuration"]["DEVICE"] == 'blinkstick':
    from blinkstick import blinkstick
    import signal
    import sys
    #Will turn all leds off when invoked.
    def signal_handler(signal, frame):
        all_off = [0]*(config.settings["configuration"]["N_PIXELS"]*3)
        stick.set_led_data(0, all_off)
        sys.exit(0)

    stick = blinkstick.find_first()
    # Create a listener that turns the leds off when the program terminates
    signal.signal(signal.SIGTERM, signal_handler)
示例#29
0
from __future__ import print_function
from __future__ import division

import platform
import numpy as np
import config

# ESP8266 uses WiFi communication
if config.DEVICE == 'esp8266':
    import socket
    _sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
# Raspberry Pi controls the LED strip directly
elif config.DEVICE == 'pi':
    import neopixel
    strip = neopixel.Adafruit_NeoPixel(config.N_PIXELS, config.LED_PIN,
                                       config.LED_FREQ_HZ, config.LED_DMA,
                                       config.LED_INVERT, config.BRIGHTNESS)
    strip.begin()
elif config.DEVICE == 'blinkstick':
    from blinkstick import blinkstick
    import signal
    import sys
    #Will turn all leds off when invoked.
    def signal_handler(signal, frame):
        all_off = [0]*(config.N_PIXELS*3)
        stick.set_led_data(0, all_off)
        sys.exit(0)

    stick = blinkstick.find_first()
    # Create a listener that turns the leds off when the program terminates
    signal.signal(signal.SIGTERM, signal_handler)
                strip.setPixelColor(i + q, 0)


# Main program logic follows:
if __name__ == '__main__':
    # Process arguments
    parser = argparse.ArgumentParser()
    parser.add_argument('-c',
                        '--clear',
                        action='store_true',
                        help='clear the display on exit')
    args = parser.parse_args()

    # Create NeoPixel object with appropriate configuration.
    strip = neopixel.Adafruit_NeoPixel(LED_COUNT, LED_PIN, LED_FREQ_HZ,
                                       LED_DMA, LED_INVERT, LED_BRIGHTNESS,
                                       LED_CHANNEL)
    # Intialize the library (must be called once before other functions).
    strip.begin()

    print('Press Ctrl-C to quit.')
    if not args.clear:
        print('Use "-c" argument to clear LEDs on exit')

    try:

        while True:
            print('Color wipe animations.')
            colorWipe(strip, neopixel.Color(255, 0, 0))  # Red wipe
            colorWipe(strip, neopixel.Color(0, 255, 0))  # Blue wipe
            colorWipe(strip, neopixel.Color(0, 0, 255))  # Green wipe