def start_strip(self): """ Start PixelStrip object :returns rpi_ws281x.PixelStrip """ self._logger.info("Initialising LED strip") strip_settings = self.settings['strip'] try: strip = PixelStrip( num=strip_settings['led_count'], pin=strip_settings['led_pin'], freq_hz=strip_settings['led_freq_hz'], dma=strip_settings['led_dma'], invert=strip_settings['led_invert'], brightness=strip_settings['led_brightness'], channel=strip_settings['led_channel'], strip_type=STRIP_TYPES[strip_settings['strip_type']]) strip.begin() self._logger.info("Strip object successfully initialised") return strip except Exception as e: # Probably wrong settings... self._logger.error( "Strip failed to initialize, no effects will be run.") self._logger.error("Please check your settings.") self._logger.error("Here's the exception: {}".format(e)) return None
def __init__(self, light_state:LightState): super().__init__() self.state = light_state self.periodic = None self.refresh_period_or_duty_cycle() self.strip = PixelStrip(self.state.get_num_pixels(), 18)
def __init__(self): self.gammaTable = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10, 10, 11, 11, 11, 12, 12, 13, 13, 13, 14, 14, 15, 15, 16, 16, 17, 17, 18, 18, 19, 19, 20, 21, 21, 22, 22, 23, 23, 24, 25, 25, 26, 27, 27, 28, 29, 29, 30, 31, 31, 32, 33, 34, 34, 35, 36, 37, 37, 38, 39, 40, 40, 41, 42, 43, 44, 45, 46, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 76, 77, 78, 79, 80, 81, 83, 84, 85, 86, 88, 89, 90, 91, 93, 94, 95, 96, 98, 99, 100, 102, 103, 104, 106, 107, 109, 110, 111, 113, 114, 116, 117, 119, 120, 121, 123, 124, 126, 128, 129, 131, 132, 134, 135, 137, 138, 140, 142, 143, 145, 146, 148, 150, 151, 153, 155, 157, 158, 160, 162, 163, 165, 167, 169, 170, 172, 174, 176, 178, 179, 181, 183, 185, 187, 189, 191, 193, 194, 196, 198, 200, 202, 204, 206, 208, 210, 212, 214, 216, 218, 220, 222, 224, 227, 229, 231, 233, 235, 237, 239, 241, 244, 246, 248, 250, 252, 255 ] self.strip = PixelStrip(LED_COUNT, LED_PIN, LED_FREQ_HZ, LED_DMA, LED_INVERT, LED_BRIGHTNESS, LED_CHANNEL) self.strip.begin() self.cols = [] self.hues = np.arange(360, step=10) for i in range(36): self.cols.append(hsv2rgb(self.hues[i] / 360, 1, 1))
def setup_led_strips(): # Create PixelStrip object with appropriate configuration global strip strip = PixelStrip(LED_COUNT, LED_PIN, LED_FREQ_HZ, LED_DMA, LED_INVERT, LED_BRIGHTNESS, LED_CHANNEL, LED_STRIP) # Initialize the library (must be called once before other functions) strip.begin()
def __init__(self, source: BasicSource, output: str): self.output = output if self.output == "STRIP": # Create NeoPixel object with appropriate configuration. self.strip = PixelStrip(App.N_LEDS, App.LED_PIN, App.LED_FREQ_HZ, App.LED_DMA, App.LED_INVERT, App.LED_BRIGHTNESS, App.LED_CHANNEL) elif self.output == "LED": self.strip = TkStrip(App.N_LEDS, self) elif self.output == "PLOT": self.strip = TkPlot(App.N_LEDS, self) elif self.output == "DUMMY": self.strip = DummyStrip() else: print("Unknown output %s" % self.output) sys.exit(-1) self.source = source self.source.init(App.N_LEDS) self.frame = 0 self.last_update = time.time_ns() self.fps_times = self.last_update # Intialize the library (must be called once before other functions). self.strip.begin() self.error_time = 0
def __init__(self, pixel_count=1, gpio_pin=13, strip_type='WS2812', channel=None, brightness=255, freq_hz=800000, dma=10, invert=False): """Initialise WS281X device. :param pixel_count: Number of individual RGB LEDs :param gpio_pin: BCM GPIO pin for output signal :param strip_type: Strip type: one of WS2812 or SK6812 :param channel: LED channel (0 or 1, or None for automatic) :param brightness: Global WS281X LED brightness scale :param freq_hz: WS281X output signal frequency (usually 800khz) :param dma: DMA channel :param invert: Invert signals for NPN-transistor based level shifters """ from rpi_ws281x import PixelStrip, ws strip_types = {} for t in ws.__dict__: if '_STRIP' in t: k = t.replace('_STRIP', '') v = getattr(ws, t) strip_types[k] = v strip_type = strip_types[strip_type] if channel is None: if gpio_pin in [13]: channel = 1 elif gpio_pin in [12, 18]: channel = 0 self._strip = PixelStrip(pixel_count, gpio_pin, freq_hz, dma, invert, brightness, channel, strip_type) self._strip.begin() Plasma.__init__(self, pixel_count)
def __init__(self, rows, columns, serial_type=1, led_pin=18): ## # serial_type 信号线连接方式, 1表示弓字形连线,2表示Z字形连线 ## self.rows = rows self.columns = columns self.led_numbers = rows * columns self._mod = 1 self.leds = [] for i in range(self.led_numbers): self.leds.append(LED(i)) self.led_index = [[0 for i in range(self.columns)] for i in range(self.rows)] if (serial_type == 1): for i in range(0, rows, 2): for j in range(0, self.columns): self.led_index[i][j] = i * self.columns + j for i in range(1, rows, 2): for j in range(0, self.columns): self.led_index[i][j] = (i + 1) * self.columns - (j + 1) elif (serial_type == 2): for i in range(0, rows): for j in range(0, columns): self.led_index[i][j] = i * self.columns + j self.strip = PixelStrip(self.led_numbers, led_pin) self.strip.begin() self.strip.setBrightness(255)
def dosetup(self): """ Init. of a default rgb strip Note: The config file need to be loaded before calling this method """ fix = 0 if self.BROKEN_PCB: fix = 1 LED_COUNT = ( (self.FRET_CNT + self.CONFIG["TOP_INSTALLED"]) * self.STRING_CNT + fix) LED_PIN = 18 LED_FREQ = 800000 LED_DMA = 10 LED_BRIGHTNESS = self.CONFIG["BRIGHTNESS"] self.LED_STRIP = PixelStrip(\ LED_COUNT,\ LED_PIN,\ LED_FREQ,\ LED_DMA,\ False,\ LED_BRIGHTNESS) self.LED_STRIP.begin()
def start_strip(self): """ Start PixelStrip object :returns strip: (rpi_ws281x.PixelStrip) The initialised strip object """ self._logger.info("Initialising LED strip") try: strip = PixelStrip( num=int(self.strip_settings["count"]), pin=int(self.strip_settings["pin"]), freq_hz=int(self.strip_settings["freq_hz"]), dma=int(self.strip_settings["dma"]), invert=bool(self.strip_settings["invert"]), brightness=int(self.strip_settings["brightness"]), channel=int(self.strip_settings["channel"]), strip_type=constants.STRIP_TYPES[self.strip_settings["type"]], ) strip.begin() self._logger.info("Strip successfully initialised") return strip except Exception as e: # Probably wrong settings... self._logger.error(repr(e)) self._logger.error( "Strip failed to initialize, no effects will be run.") raise StripFailedError("Error intitializing strip")
def pixel_strip(): """ Initialized and started PixelStrip fixture """ ps = PixelStrip(NUM_PIXELS, 0) ps.begin() return ps
def setup_strip(): global LED_BRIGHTNESS global which_effect which_effect = False # LED strip configuration: LED_COUNT = 300 # 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 = 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 # set to '1' for GPIOs 13, 19, 41, 45 or 53 strip = PixelStrip( 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). logger.debug(f"Setting up strip") strip.begin() clear_strip(strip) return strip
def __init__(self, pin: int, nb_led: int = 5): self.pixels = PixelStrip(nb_led, pin) self.pixels.begin() self._state: bool = False self.delay: float = 0.01 self._mode: int = MODE_RGB self.off()
def __init__(self): if LedManager.__instance is None: LedManager.__instance = self self.strip = PixelStrip(self.__LED_COUNT, self.__LED_PIN, self.__LED_FREQ_HZ, self.__LED_DMA, self.__LED_INVERT, self.__LED_BRIGHTNESS, self.__LED_CHANNEL, self.__LED_STRIP) self.strip.begin() else: raise Exception("This class is a Singleton")
def __init__(self, pixels): # the imports must be hidden since they won't work on pc from rpi_ws281x import PixelStrip # init the pixel strip self.np = PixelStrip(pixels, 18, LED_FREQ_HZ, LED_DMA, LED_INVERT, LED_BRIGHTNESS, LED_CHANNEL) self.np.begin() self.pixel_count = pixels
def __init__(self, width, height, serpentine=False, name=None): self.serpentine = serpentine super().__init__(np.zeros((height, width, 3), dtype=np.uint8), 8, name=name) self.pixelstrip = PixelStrip(self.height * self.width, LED_PIN, LED_FREQ_HZ, LED_DMA, LED_INVERT, LED_BRIGHTNESS, LED_CHANNEL, LED_GAMMA)
def __init__(self, width, height, led_pin=18, map=None, name=None): self.map = map if self.map is None: n_leds = self.height * self.width else: n_leds = len(self.map) super().__init__(np.zeros((height, width, 3), dtype=np.uint8), 8, name=name) self.pixelstrip = PixelStrip(n_leds, led_pin, LED_FREQ_HZ, LED_DMA, LED_INVERT, LED_BRIGHTNESS, LED_CHANNEL, LED_GAMMA)
def __init__(self, LED_COUNT, LED_PIN, LED_FREQ_HZ, LED_DMA, LED_INVERT, LED_BRIGHTNESS, LED_CHANNEL, LED_STRIP): self._strip = PixelStrip(LED_COUNT, LED_PIN, LED_FREQ_HZ, LED_DMA, LED_INVERT, LED_BRIGHTNESS, LED_CHANNEL, LED_STRIP) self._strip.begin() self._step = 0.5 self._start = 0
def __init__(self, pixels): # the imports must be hidden since they won't work on pc from rpi_ws281x import PixelStrip # init the pixel strip self.np = PixelStrip(pixels, PIN) self.np.begin() self.pixel_count = pixels self.is_stopped = False
def __init__(self): # strip = None # self.DotCount = LED_COUNT # Create NeoPixel object with appropriate configuration. self.strip = PixelStrip(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() self.DotCount = self.strip.numPixels()
def __init__(self): # Create NeoPixel object with appropriate configuration. self.strip = PixelStrip(self.LED_COUNT, self.LED_PIN, 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.colorFill(Color(0, 0, 0, 0))
def __init__(self, led_count, led_pin, led_freq_hz, led_dma, led_invert, led_brightness, led_channel): self.strip = PixelStrip(led_count, led_pin, led_freq_hz, led_dma, led_invert, led_brightness, led_channel) self.strip.begin() self.led_count = led_count self.pixels = [Pixel(self.strip, x) for x in range(led_count)] signal.signal(signal.SIGINT, self.signal_handler)
def run(self): # Create NeoPixel object with appropriate configuration. strip = PixelStrip(self.LED_COUNT, self.LED_PIN, self.LED_FREQ_HZ, self.LED_DMA, self.LED_INVERT, self.LED_BRIGHTNESS, self.LED_CHANNEL) try: return strip except KeyboardInterrupt: # clean the matrix LED before interruption self.clean(strip)
def Start(self): """ Initialize the LED strip at the hardware level so that we can start control the individual LEDs. """ self._strip=PixelStrip(self._ledCount, \ self._stripGpioPin, \ self._ledFrequency, \ self._ledDmaChannel, \ self._ledInvert, \ self._ledBrightness, \ self._ledChannel, \ self._stripType) # Initialize the library (must be called once before other functions): self._strip.begin()
def __init__(self): # Create NeoPixel object with appropriate configuration. self.strip = PixelStrip(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() for i, led_counter in enumerate(NUMBER_OF_LEDS): # get last led start = 0 if i == 0 else (self[-1][-1] + 1) # define step step = Step(self.strip, start, start + led_counter) self.append(step)
def init(): global strip LED_COUNT = cfg["WS8211"].getint("count", 6) LED_PIN = cfg["WS8211"].getint("pin", 12) LED_FREQ_HZ = cfg["WS8211"].getint("frequence", 800000) LED_DMA = cfg["WS8211"].getint("dma", 10) LED_INVERT = cfg["WS8211"].getboolean("invert", False) LED_BRIGHTNESS = cfg["WS8211"].getint("brightness", 50) LED_CHANNEL = cfg["WS8211"].getint("channel", 0) strip = PixelStrip(LED_COUNT, LED_PIN, LED_FREQ_HZ, LED_DMA, LED_INVERT, LED_BRIGHTNESS, LED_CHANNEL) strip.begin()
def setup_pin(self): if bool(self._settings.get([IS_LED_STRIP])): # enabling led strip on selected pin self.pixels = PixelStrip( int(self._settings.get([NB_LEDS])), int(self._settings.get([LIGHT_PIN])), LED_FREQ_HZ, LED_DMA, bool(self._settings.get([INVERTED_OUTPUT])), LED_BRIGHTNESS, LED_CHANNEL, LED_STRIP) self.pixels.begin() else: # Sets the GPIO every time, if user changed it in the settings. GPIO.setup(int(self._settings.get([LIGHT_PIN])), GPIO.OUT)
def main(): parser = argparse.ArgumentParser( description='Project an image onto a LED matrix.') parser.add_argument('filename', type=str, help='filename of the image to display') parser.add_argument('boardsize', type=int, help='the width and height of the LED matrix') parser.add_argument('gpionum', type=int, help='the target GPIO pin') parser.add_argument('--verbose', '-v', action='store_true', help='enables verbose output') args = parser.parse_args() global VERBOSE VERBOSE = args.verbose try: from rpi_ws281x import PixelStrip except ImportError: class PixelStrip(): """PixelStrip stub.""" def __init__(self, *args, **kwargs): print( "rpi_ws281x not found - this won't actually draw anything." ) def begin(self): pass def setPixelColorRGB(self, *args): pass def show(self): print("Done mock drawing.") np = PixelStrip(args.boardsize**2, args.gpionum, brightness=LED_INTENSITY) np.begin() my_grid = led_grid.LEDGrid(np, grid.SerpentinePattern.TOP_RIGHT, args.boardsize, args.boardsize) image = process_image(args.filename, args.boardsize) draw_led_matrix(my_grid, image) np.show() try: terminal_output.print_led_grid(my_grid) except: traceback.print_exc()
def __init__(self): gamma = self.__gammaTable(self.LED_GAMMA) self.strip = PixelStrip( num = self.MATRIX_HEIGHT * self.MATRIX_WIDTH, pin = self.LED_PIN, freq_hz = self.LED_FREQ_HZ, dma = self.LED_DMA, invert = self.LED_INVERT, brightness = self.LED_BRIGHTNESS, channel = self.LED_CHANNEL, strip_type = self.LED_TYPE, gamma = gamma )
class Lights(): # LED st£rip configuration: LED_COUNT = 8 # 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 = 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 # set to '1' for GPIOs 13, 19, 41, 45 or 53 BF_LED = 11 disp_r = True disp_g = True disp_b = True strip = PixelStrip(LED_COUNT, LED_PIN, LED_FREQ_HZ, LED_DMA, LED_INVERT, LED_BRIGHTNESS, LED_CHANNEL) init = False def __init__(self): if not Lights.init: print("Initing") Lights.init = True Lights.strip.begin() GPIO.setup(Lights.BF_LED, GPIO.OUT) for i in range(0, Lights.strip.numPixels()): Lights.strip.setPixelColor(i, Color(255, 255, 255)) Lights.strip.show() def df(self, color): if color == 'r': Lights.disp_r = not Lights.disp_r elif color == 'g': Lights.disp_g = not Lights.disp_g elif color == 'b': Lights.disp_b = not Lights.disp_b for i in range(0, Lights.strip.numPixels()): Lights.strip.setPixelColor( i, Color( int(Lights.disp_r) * 255, int(Lights.disp_g) * 255, int(Lights.disp_b) * 255)) Lights.strip.show() def bf(self): GPIO.output(Lights.BF_LED, int(not GPIO.input(Lights.BF_LED)))
def setup(): global ws2812, _is_setup if _is_setup: return ws2812 = PixelStrip(LED_COUNT, LED_PIN, LED_FREQ_HZ, LED_DMA, LED_INVERT, LED_BRIGHTNESS, LED_CHANNEL, LED_GAMMA) ws2812.begin() set_layout(HAT) atexit.register(_clean_shutdown) _is_setup = True