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()
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)
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
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"])
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()
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
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()
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()
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
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()
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!')
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()
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)
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()
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)
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
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()
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
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])
class LedsNeoPixel(LedsSoft): # pragma: no cover 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 # True to invert the signal (when using NPN transistor level shift) LED_INVERT = False LED_CHANNEL = 1 # set to '1' for GPIOs 13, 19, 41, 45 or 53 LED_COUNT = 5 PULSING_RATE = 0.100 # every 100ms 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() def do_set(self, led, red, green, blue): # NeoPixel indexes on the strip do match the (original) values led_ix = led.value self.strip.setPixelColor(led_ix, Color(red, green, blue)) def do_show(self): self.strip.show()
class LedsModule(BaseModule): def __init__(self, config_file, secure_file): BaseModule.__init__(self, config_file, secure_file) try: self.neopixel_pin = self.config['neopixel_pin'] except KeyError as e: logger = logging.getLogger(__name__) err = "Key error in LEDS Init: {}".format(e) logger.error(err) self.mqtt_client.publish('gserv/error', err) sys.exit(2) self.pattern_classes = { "BLANK": SolidPattern, "GREEN_CLOCKWISE": SpinPattern, "GREEN_COUNTERCLOCKWISE": SpinPattern, "RED_CLOCKWISE": SpinPattern, "RED_COUNTERCLOCKWISE": SpinPattern, "BLUE_CLOCKWISE": SpinPattern, "BLUE_COUNTERCLOCKWISE": SpinPattern, "CYAN_CLOCKWISE": SpinPattern, "CYAN_COUNTERCLOCKWISE": SpinPattern, "COUNTDOWN": CountdownPattern } self.current_pattern = None def run(self): self.strip = Adafruit_NeoPixel(8, self.neopixel_pin, 800000, 10, False, 255, 0) self.strip.begin() self.change_pattern("BLANK") self.mqtt_client.loop_forever() def change_pattern(self, pattern_name): if self.current_pattern is not None: self.current_pattern.stop() if pattern_name in self.pattern_classes: self.current_pattern = self.pattern_classes[pattern_name]( self, pattern_name, self.config) self.current_pattern.start() else: self.current_pattern = None def on_message(self, client, userdata, message): logger = logging.getLogger(__name__) msg = message.payload.decode('utf-8') logger.debug(msg) self.change_pattern(msg) def writeSPIData(self, ledList): led_index = 0 for l in ledList: self.strip.setPixelColorRGB(led_index, l[1], l[0], l[2]) led_index += 1 self.strip.show()
def __init__(self, strip: Adafruit_NeoPixel, num_segments: int, leds_per_segment: int): required_leds = num_segments * leds_per_segment if strip.numPixels() < num_segments * leds_per_segment: raise ValueError( f"LED strip has {strip.numPixels()} pixels but requires {required_leds}" ) self.strip = strip self.num_segments = num_segments self.leds_per_segment = leds_per_segment self._black_color = Color(0, 0, 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
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()
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)
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)
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()
class LED(): 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() def colorWipe(self, rgb, wait_ms=50): """Wipe color across display a pixel at a time. :param rgb: color :type rgb: tuple(int, int, int) """ color = Color(*rgb) for i in range(self.strip.numPixels()): self.strip.setPixelColor(i, color) self.strip.show() time.sleep(wait_ms / 10000.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()
class LedControl: 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() def color_wipe(self, color): """Wipe color across display a pixel at a time.""" for i in range(self.strip.numPixels()): self.strip.setPixelColor(i, color) self.strip.show() def transition_to_white(self, steps=18000, timestep=100): """ Transition all leds to white :param steps: number of steps in transition :param timestep: time that one step takes in ms """ final_color = np.array([255, 255, 255]) start_color = np.array([0, 0, 0]) color_delta = final_color - start_color for i in range(steps): # create linear i in range 0 to 100 lin_range = i / (steps - 1) * 100 # create exponential range from 1 to exp(100) log_range = np.exp(lin_range) # create exponential range from 0 to 1 log_range = (log_range - 1) / (np.exp(100) - 1) color = start_color + color_delta * lin_range / 100 # log_range self.color_wipe(Color(int(color[0]), int(color[1]), int(color[2]))) time.sleep(timestep / 1000)