Example #1
0
 def __init__():
     strip0 = Adafruit_NeoPixel(self.LED_COUNT, self.LED_0_PIN, self.LED_FREQ_HZ,
                                self.LED_0_DMA, self.LED_INVERT, self.LED_BRIGHTNESS,
                                self.LED_0_CHANNEL, self.LED_STRIP)
     strip1 = Adafruit_NeoPixel(self.LED_COUNT, self.LED_1_PIN, self.LED_FREQ_HZ,
                                self.LED_1_DMA, self.LED_INVERT, self.LED_BRIGHTNESS,
                                self.LED_1_CHANNEL, self.LED_STRIP)
Example #2
0
def on_connect(client, userdata, flags, rc):
    global strip_odd
    global strip_even

    strip_odd = Adafruit_NeoPixel(LED_COUNT, 12, LED_FREQ_HZ, LED_DMA,
                                  LED_INVERT, LED_BRIGHTNESS, 0)
    strip_even = Adafruit_NeoPixel(LED_COUNT, 13, LED_FREQ_HZ, LED_DMA,
                                   LED_INVERT, LED_BRIGHTNESS, 1)

    strip_3 = Adafruit_NeoPixel(LED_COUNT, 18, LED_FREQ_HZ, LED_DMA,
                                LED_INVERT, LED_BRIGHTNESS, 0)
    strip_4 = Adafruit_NeoPixel(LED_COUNT, 19, LED_FREQ_HZ, LED_DMA,
                                LED_INVERT, LED_BRIGHTNESS, 1)

    strip_odd.begin()
    strip_even.begin()
    strip_3.begin()
    strip_4.begin()

    #Blackout
    blackout(strip_odd)
    blackout(strip_even)
    blackout(strip_3)
    blackout(strip_4)

    client.subscribe("shelf/#")

    publish.single("shelf/report/status", 'false', hostname="localhost")
    publish.single("shelf/report/brightness", '0', hostname="localhost")
    publish.single("shelf/report/hue", '0', hostname="localhost")
    publish.single("shelf/report/saturation", '0', hostname="localhost")
Example #3
0
def set_leds(shutdown):
    LED_COUNT = 5
    LED_PIN = 13  # GPIO pin connected to the pixels (18 uses PWM!).
    LED_FREQ_HZ = 800000  # LED signal frequency in hertz (usually 800khz)
    LED_DMA = 12  # DMA channel to use for generating signal (try 10)
    LED_BRIGHTNESS = 200  # 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 = 1  # set to '1' for GPIOs 13, 19, 41, 45 or 53

    strip = 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()

    if shutdown:
        color = Color(0, 0, 0)
    else:
        color = Color(255, 0, 255)

    for led in range(6):
        strip.setPixelColor(led, color)

    strip.show()
Example #4
0
    def __init__(self, imageQueue):

        self.imageQueue = imageQueue
        self.capture = False
        self.capture_thread = None
        self.cap = cv2.VideoCapture(constants.CAMERA_NUM - 1 + cv2.CAP_ANY)

        self.UV_LED = False
        self.COLOR_LED = False

        if not testMode:
            GPIO.setmode(GPIO.BOARD)
            GPIO.setup(constants.GPIO_UV_LED, GPIO.OUT)
            self.UV_LED_PWM = GPIO.PWM(constants.GPIO_UV_LED,
                                       800)  # channel=12 frequency=50Hz
            self.UV_LED_PWM.start(0)

            self.strip = Adafruit_NeoPixel(constants.COLOR_LED_NUM,
                                           constants.GPIO_COLOR_LED,
                                           dma=10)
            self.strip.begin()
            for n in range(constants.COLOR_LED_NUM):
                self.strip.setPixelColorRGB(
                    n, constants.settings["Color"]["LED_Red"],
                    constants.settings["Color"]["LED_Green"],
                    constants.settings["Color"]["LED_Blue"])
Example #5
0
 def __init__(self):
     # Create NeoPixel object with appropriate configuration.
     self.strip = 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).
     self.strip.begin()
Example #6
0
def main(agent_id):
    # 根据agent_id点亮不同位置的灯区分树莓派 1 2 3
    print('suceess0:the number of this pi is %d:', agent_id)
    strip = Adafruit_NeoPixel(32, 18, 800000, 10, False, 10)
    strip.begin()
    strip.setPixelColor(agent_id, Color(255, 0, 0))
    strip.show()

    context = zmq.Context()
    publisher = context.socket(zmq.PUB)
    publisher.connect("tcp://%s:5556" % broker_ip)
    print("success1: begin zmq")
    subscriber = context.socket(zmq.SUB)
    subscriber.connect("tcp://%s:5555" % broker_ip)
    # subscriber.setsockopt_string(zmq.SUBSCRIBE, str(agent_id))
    while True:
        flag = 0
        #message = subscriber.recv()
        r = scan_wifi()
        print("success2:scan_wifi")
        info = r.readlines()
        print("success3:read lines")
        for line in info:
            line = line.strip('\r\n')
            # print(line)
            mac = line[0:17]
            # 移动终端的mac地址
            if (mac == '54:25:ea:4c:22:c0') | (mac == '74:60:fa:81:a8:d8'):
                print('%d: %s' % (agent_id, line))
                publisher.send_string('%d: %s' % (13, line))
                flag = 1
        if flag == 0:
            print('haha')
            time.sleep(0.2)
Example #7
0
    def __init__(
            self, num, gamma=gamma.NEOPIXEL, c_order="RGB", gpio=18,
            ledFreqHz=800000, ledDma=5, ledInvert=False,
            color_channels=3, brightness=255, **kwds):

        if not NeoColor:
            raise ValueError(WS_ERROR)
        super().__init__(num, c_order=c_order, gamma=gamma, **kwds)
        self.gamma = gamma
        if gpio not in PIN_CHANNEL.keys():
            raise ValueError('{} is not a valid gpio option!')
        try:
            strip_type = STRIP_TYPES[color_channels]
        except:
            raise ValueError('In PiWS281X, color_channels can only be 3 or 4')

        self._strip = Adafruit_NeoPixel(
            num, gpio, ledFreqHz, ledDma, ledInvert, brightness,
            PIN_CHANNEL[gpio], strip_type)
        # Intialize the library (must be called once before other functions).
        try:
            self._strip.begin()
        except RuntimeError as e:
            if os.geteuid():
                if os.path.basename(sys.argv[0]) in ('bp', 'bibliopixel'):
                    command = ['bp'] + sys.argv[1:]
                else:
                    command = ['python'] + sys.argv
                error = SUDO_ERROR.format(command=' '.join(command))
                e.args = (error,) + e.args
            raise
Example #8
0
 def _setup(self):
     """Setups the hardware strip"""
     if self.strip is None:
         strip = Adafruit_NeoPixel(self._ledCount, self._ledPin,
                                   self._ledFreqHz, self._ledDma,
                                   self._ledInvert, self._ledBrightness,
                                   self._ledChannel)
         strip.begin()
         return strip
Example #9
0
 def __init__(self):
     super().__init__()
     self.strip = Adafruit_NeoPixel(
         LedsNeoPixel.LED_COUNT, LedsNeoPixel.LED_PIN,
         LedsNeoPixel.LED_FREQ_HZ, LedsNeoPixel.LED_DMA,
         LedsNeoPixel.LED_INVERT, LedsNeoPixel.LED_BRIGHTNESS,
         LedsNeoPixel.LED_CHANNEL)
     # Intialize the library (must be called once before other functions).
     self.strip.begin()
Example #10
0
    def start(self):
        """Initialize hardware and os resources."""
        # Create NeoPixel object with appropriate configuration.
        self.strip = Adafruit_NeoPixel(self.led_count, self.led_pin,
                                       int(self.led_freq_hz), self.led_dma,
                                       self.led_invert, self.led_brightness,
                                       self.led_channel, self.led_strip)

        # Intialize the library (must be called once before other functions).
        self.strip.begin()
        self.strip.show()
Example #11
0
 def initialize(self):
     '''
     Use this method to reinitialize the connection to the neopixels when an exception occurs.
     '''
     try:
         self._pixels = Adafruit_NeoPixel(self._no_leds, self._port, 800000,
                                          10, False, 255)
         self._pixels.begin()
         self._failed = False
     except Exception as error:
         self._failed = True
Example #12
0
 def __init__(self):
     self.strip = Adafruit_NeoPixel(
         LED_COUNT,
         LED_PIN,
         LED_FREQ_HZ,
         LED_DMA,
         LED_INVERT,
         LED_BRIGHTNESS,
         LED_CHANNEL,
     )
     self.strip.begin()
Example #13
0
 def __init__(self):
     # LED strip configuration:
     self._LED_COUNT = 4  # Number of LED pixels.
     self._LED_PIN = 18  # GPIO pin connected to the pixels (must support PWM!).
     self._LED_FREQ_HZ = 800000  # LED signal frequency in hertz (usually 800khz)
     self._LED_DMA = 5  # DMA channel to use for generating signal (try 5)
     self._LED_BRIGHTNESS = 255  # Set to 0 for darkest and 255 for brightest
     self._LED_INVERT = False  # True to invert the signal (when using NPN transistor level shift)
     self._LED_CHANNEL = 0
     self._strip = Adafruit_NeoPixel(self._LED_COUNT, self._LED_PIN, self._LED_FREQ_HZ, self._LED_DMA, self._LED_INVERT, self._LED_BRIGHTNESS)
     self._strip.begin()
     self.switchOffStrip()
Example #14
0
 def __init__(self):
     threading.Thread.__init__(self)
     self.thread_name = "RGB_LIGHT"
     self.strip = Adafruit_NeoPixel(configs.LED_COUNT, configs.LED_PIN,
                                    configs.LED_FREQ_HZ, configs.LED_DMA,
                                    configs.LED_INVERT,
                                    configs.LED_BRIGHTNESS)
     self.strip.begin()
     init_color = Color(0, 0, 0)
     self.led_colors = [init_color for i in range(configs.LED_COUNT)]
     # 预警返回值,如果为1,则需要颜色预警
     self.remind_type = 0
     my_print(self, 'init done!')
Example #15
0
    def __init__(self, count, pin=21, br=100):
        """
        LEDs
        """
        self.LED_COUNT = count
        LED_PIN = pin  # GPIO пин, к которому вы подсоединяете светодиодную ленту
        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 = br  # 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

        self.strip = Adafruit_NeoPixel(self.LED_COUNT, LED_PIN, LED_FREQ_HZ,
                                       LED_DMA, LED_INVERT)
        self.strip.begin()
Example #16
0
    def __init__(self, led_count, led_gpio):
        try:
            from rpi_ws281x import Adafruit_NeoPixel

            self.strip = Adafruit_NeoPixel(led_count, led_gpio)
            self.strip.begin()
        except:
            self.strip = Mock_Adafruit_NeoPixel(led_count, led_gpio)
            self.strip.begin()

        self.hsv = [0, 0, 0]
        self.status = True
        self.event_running = False

        # On start changes values to black.
        self.set_color(self.hsv)
Example #17
0
def main():
    # 根据agent_id点亮不同位置的灯区分树莓派 1 2 3
    print('suceess0:the number of this pi is %d:', agent_id)
    strip = Adafruit_NeoPixel(32, 18, 800000, 10, False, 10)
    strip.begin()
    strip.setPixelColor(agent_id, Color(255, 0, 0))
    strip.show()

    print('suceess1:begin thread')
    # 创建新线程
    thread1 = myThread1(1, "Thread-1", 1)
    thread2 = myThread1(2, "Thread-2", 2)

    # 开启线程
    thread1.start()
    thread2.start()
Example #18
0
 def add_stripe(
         self,
         NUMPIXELS,  # Amount of pixels (LEDs) the strip contains
         PIN,  # GPIO pin the strip is connected to (must be PWM pin, RPi4: 12, 13, 18, 19)
         FREQUENCY_HZ=800000,  # PWM Frequency the strip operates in
         DMA_CHANNEL=10,  # DMA Channel (1 to 14) 
         PWM_CHANNEL=0,  # PWM Channel (0 or 1)
         BRIGHTNESS=128,  # For strips that support brightness control (0 to 255)
         INVERT=False,  # If using a level shifter that causes signal inversion, set this to true
         STRIP_TYPE='WS2811_STRIP_GRB',  # Available types [WS2811_STRIP_GRB, ]
 ):
     strip = Adafruit_NeoPixel(NUMPIXELS, PIN, FREQUENCY_HZ, DMA_CHANNEL,
                               INVERT, BRIGHTNESS, PWM_CHANNEL,
                               self.strip_types[STRIP_TYPE])
     strip.begin()
     self.strips.append(strip)
Example #19
0
 def __init__(self):
     self._kill_previous_process()
     self._animations_dir = os.path.join(os.getcwd(), 'animations')
     self._frame_handlers = {
         ord('P'): self._on_pframe,
         ord('I'): self._on_iframe,
         ord('D'): self._on_dframe,
         ord('F'): self._on_fframe
     }
     settings = self._load_settings()
     brightness = settings['brightness'] * 255 // 50
     self._strip = Adafruit_NeoPixel(LED_COUNT, LED_PIN, LED_FREQ_HZ,
                                     LED_DMA, LED_INVERT, brightness,
                                     LED_CHANNEL)
     self._strip.begin()
     self._strip.setBrightness(50)
     self._animation = None
Example #20
0
 def _setup(self):
     for i in range(self.led_strip_count):
         self.pixels.append(Pixels(self.led_count))
         args = AnimationArgs()
         args.animation = Animations.color
         args.color = 0
         self.pixels[i].animation(args)
         self.strip.append(
             Adafruit_NeoPixel(
                 self.led_count,
                 self.pin,
                 LED_FREQ_HZ,
                 LED_DMA,
                 LED_INVERT,
                 self.max_brightness,
                 self.led_channel,
             ))
         if not self.testing:
             self.strip[i].begin()
Example #21
0
 def __init__(self,
              name,
              parent,
              ledCount,
              ledPin,
              freq=800000,
              dmaChannel=10,
              invert=False,
              brightness=255,
              ledChannel=0,
              debug=False):
     """ construct a strip led """
     super(PiStripLed, self).__init__(name, parent)
     self.debug = debug
     # Create NeoPixel object with appropriate configuration.
     self.strip = Adafruit_NeoPixel(ledCount, ledPin, freq, dmaChannel,
                                    invert, brightness, ledChannel)
     # Intialize the library (must be called once before other functions).
     self.strip.begin()
Example #22
0
 def __init__(self,
              led_count=60,
              led_pin=18,
              sections={'default': range(0, 60)},
              virtual_sections={}):
     """Creates a new Led_Controller Manager.
     led_count: Total number of LED pixels physically connected to this Pi
     led_pin: GPIO pin connected to the pixels (must support PWM!)
     sections: The named led sections that can be controlled
     virtual_sections: The names of the sections that are not connected to this device
     and their respective controller modules.
     """
     if led_count > 0:
         from rpi_ws281x import Adafruit_NeoPixel, WS2812_STRIP
         LED_STRIP = WS2812_STRIP  #Uses GBR instead of RGB
         self.ws2812 = Adafruit_NeoPixel(led_count, led_pin, LED_FREQ_HZ,
                                         LED_DMA, LED_INVERT,
                                         LED_BRIGHTNESS, LED_CHANNEL,
                                         LED_STRIP)
         self.ws2812.begin()
     self.controllers = []
     self.sections = sections
     self.section_ordered = sorted(self.sections,
                                   key=lambda e: self.sections[e][-1])
     self.virtual_sections = virtual_sections
     #Number of leds in all sections, local and virtual
     self.total_leds = max(r[-1] + 1 for r in self.sections.values())
     #A mapping from absolute index to (local index, controller)
     #"Local pixels" will be formatted as (index, self.ws2182)
     self.pixel_locations = [-1] * self.total_leds
     local_index = 0
     for section_name in self.section_ordered:
         if section_name in virtual_sections:
             virtual_index = 0
             for i in self.sections[section_name]:
                 self.pixel_locations[i] = (
                     virtual_index, self.virtual_sections[section_name])
                 virtual_index += 1
         else:
             for i in self.sections[section_name]:
                 self.pixel_locations[i] = (local_index, self.ws2812)
                 local_index += 1
Example #23
0
 def __init__(self, brightness=None):
     if brightness == None:
         brightness = cs.LED_STRIP_BRIGHTNESS
     if brightness < 0:
         brightness = 0
     elif brightness > 255:
         brightness = 255
     self.strip = Adafruit_NeoPixel(cs.LED_COUNT, cs.LED_PIN,
                                    cs.LED_FREQ_HZ, cs.LED_DMA,
                                    cs.LED_INVERT, brightness,
                                    cs.LED_CHANNEL)
     self.strip.begin()
     self.OFF_COLOR = Color(0, 0, 0)
     self.R = Color(255, 0, 0)
     self.G = Color(0, 255, 0)
     self.B = Color(0, 0, 255)
     self.W = Color(255, 255, 255)
     self.DEFAULT_COLOR = Color(cs.LED_STRIP_DEFAULT_COLOR[0],
                                cs.LED_STRIP_DEFAULT_COLOR[1],
                                cs.LED_STRIP_DEFAULT_COLOR[2])
Example #24
0
    def _init_ws2812(self):
        from rpi_ws281x import Adafruit_NeoPixel, WS2812_STRIP

        LED_FREQ_HZ = 800000  # LED signal frequency in hertz (usually 800khz)
        LED_DMA = 10  # DMA channel to use for generating signal (try 5)
        LED_BRIGHTNESS = 255  # Set to 0 for darkest and 255 for brightest
        # True to invert the signal (when using NPN transistor level shift)
        LED_INVERT = False
        LED_CHANNEL = 0

        LED_STRIP = WS2812_STRIP
        ws2812 = Adafruit_NeoPixel(
            self.size,
            self.pin,
            LED_FREQ_HZ,
            LED_DMA,
            LED_INVERT,
            LED_BRIGHTNESS,
            LED_CHANNEL,
            LED_STRIP,
        )
        ws2812.begin()
        return ws2812
Example #25
0
def main():
    # 根据agent_id点亮不同位置的灯区分树莓派 1 2 3
    print('suceess0:the number of this pi is %d:',agent_id)
    strip = Adafruit_NeoPixel(32, 18, 800000, 10, False, 10)
    strip.begin()
    strip.setPixelColor(agent_id, Color(255, 0, 0))
    strip.show()
    
#     context = zmq.Context()
#     publisher = context.socket(zmq.PUB)
#     publisher.connect("tcp://%s:5556" % broker_ip)

#     subscriber = context.socket(zmq.SUB)
#     subscriber.connect("tcp://%s:5555" % broker_ip)
#     subscriber.setsockopt_string(zmq.SUBSCRIBE, str(agent_id))
    print('suceess1:begin thread')
    # 创建新线程
    thread1 = myThread1(1, "Thread-1", 1)
    thread2 = myThread1(2, "Thread-2", 2)
 
    # 开启线程
    thread1.start()
    thread2.start()
Example #26
0
    def __init__(self, window_name="PiCamera", algorithm=None):
        # Ensure object is created in RPi
        if not self.can_run():
            raise RuntimeError("PiCamera only allowed to be run via RPi. "
                               "Please use camera.Webcam for testing purposes.")

        from picamera.array import PiRGBArray
        from picamera import PiCamera

        # define camera
        self.camera = PiCamera()
        self.camera.resolution = (CAMERA_WIDTH, CAMERA_HEIGHT)
        self.camera.framerate = 30
        # grab reference to the raw camera capture
        self.rawCapture = PiRGBArray(self.camera)

        # setup lights
        from rpi_ws281x import Adafruit_NeoPixel, Color
        self.strip = Adafruit_NeoPixel(8, 18, 800000, 10, False, 255, 0)
        self.strip.begin()

        # Allow camera to warm up
        time.sleep(0.1)
        super().__init__(window_name, algorithm)
Example #27
0

if __name__ == '__main__':
    args = process_args()

    if args.length <= 0:
        print("Not enough LED to work with!")
        sys.exit()

    print("Pin used %d" % args.pin)

    pwm_channel = 0
    if args.pin in CHANNEL_1_PWM_PINS:
        pwm_channel = 1

    strip = Adafruit_NeoPixel(args.length, args.pin, LED_FREQ_HZ, LED_DMA,
                              LED_INVERT, args.brightness, pwm_channel)
    strip.begin()

    if args.check:
        try:
            light_check(strip)
        except KeyboardInterrupt:
            print("\nKeyboard Interrupt signal received.")
            if not args.donotclear:
                print("Clearing all LEDs...")
                color_wipe(strip, COLOR_BLACK, wait_ms=5)
        finally:
            sys.exit()

    if not args.job:
        print(
Example #28
0
 def __init__(self, led_count, led_pin, led_freq_hz, led_dma, led_invert, led_brightness, led_channel):
     self.strip = Adafruit_NeoPixel(led_count, led_pin, led_freq_hz, led_dma, led_invert, led_brightness,
                                    led_channel)
     self.strip.begin()
Example #29
0
            time.sleep(wait_ms / 1000.0)

    time.sleep(1)


def blackout(strip):
    for i in range(max(strip.numPixels(), strip.numPixels())):
        strip.setPixelColor(i, Color(0, 0, 0))
        strip.show()


# Main program logic follows:
if __name__ == '__main__':
    # Create NeoPixel objects with appropriate configuration for each strip.
    strip1 = Adafruit_NeoPixel(LED_1_COUNT, LED_1_PIN, LED_1_FREQ_HZ,
                               LED_1_DMA, LED_1_INVERT, LED_1_BRIGHTNESS,
                               LED_1_CHANNEL, LED_1_STRIP)

    strip2 = Adafruit_NeoPixel(LED_2_COUNT, LED_2_PIN, LED_2_FREQ_HZ,
                               LED_2_DMA, LED_2_INVERT, LED_2_BRIGHTNESS,
                               LED_2_CHANNEL, LED_2_STRIP)

    # Intialize the library (must be called once before other functions).
    strip1.begin()
    strip2.begin()

    print('Press Ctrl-C to quit.')

    # Black out any LEDs that may be still on for the last run
    blackout(strip1)
    blackout(strip2)
Example #30
0
import time, threading
# sudo pip install rpi_ws281x
from rpi_ws281x import Adafruit_NeoPixel, Color
import socket  #ip

# LED strip configuration:
LED_COUNT = 4  # Number of LED pixels.
LED_PIN = 18  # GPIO pin connected to the pixels (must support PWM!).
LED_FREQ_HZ = 800000  # LED signal frequency in hertz (usually 800khz)
LED_DMA = 5  # DMA channel to use for generating signal (try 5)
LED_BRIGHTNESS = 255  # 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

# Create NeoPixel object with appropriate configuration.
strip = 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()
strip.show()

rgb = 0
light_type = 'static'  #'static':静态 'breath':呼吸 'flash':闪烁


#访问文件根目录
@get("/")
def index():
    global rgb, light_type
    rgb = 0xffffff
    light_type = 'static'
    return static_file('index.html', './')