def __init__(self, count, data, clock=None, apa102c=False): """Initializes the LED driver Parameters ---------- count : int Required Number of LEDs in the LED strip/matrix data : int Required Pin of the Data Line clock : int Optional Pin for the clock Line. Used only by the APA102 apa102c : bool Optional Used only by the APA102C to reorder the color sequence """ data_pin = Pin(data, Pin.OUT) self.neopixel = True if clock is None: self.leds = NeoPixel(data_pin, count) else: self.neopixel = False clock_pin = Pin(clock, Pin.OUT) self.leds = APA102(data_pin, clock_pin, count) if apa102c: self.leds.ORDER = (0, 2, 1, 3) self.count = count
def __init__(self, count, data, clock=None, apa102c=False): data_pin = Pin(data, Pin.OUT) self.neopixel = True if clock is None: self.leds = NeoPixel(data_pin, count) else: self.neopixel = False clock_pin = Pin(clock, Pin.OUT) self.leds = APA102(data_pin, clock_pin, count) if apa102c: self.leds.ORDER = (0, 2, 1, 3) self.count = count
def __init__(self, pattern=AlexaLedPattern): self.pattern = pattern(show=self.show) self.dev = APA102(num_led=self.NUM_LEDS) self.power = LED(5) self.power.on() self.queue = Queue() self.thread = Thread(target=self._run) self.thread.daemon = True self.thread.start() self.last_direction = None
def record(): en = mraa.Gpio(12) if os.geteuid() != 0: time.sleep(1) en.dir(mraa.DIR_OUT) en.write(0) device = APA102(12) device.set_pixel(0, 0, 0, 3, 100) global selected if (lowPower): selected = len(interval) - 1 for count in range(2): p = pyaudio.PyAudio() stream = p.open(format=FORMAT, channels=CHANNELS, rate=RATE, input=True, frames_per_buffer=CHUNK) print("* recording") frames = [] for i in range(0, int(RATE / CHUNK * RECORD_SECONDS)): data = stream.read(CHUNK) frames.append(data) print("* done recording") stream.stop_stream() stream.close() p.terminate() derivedtime = str(datetime.now().time()) currenttime = re.sub('[' + string.punctuation + ']', ' ', derivedtime).split() wf = wave.open( "recordat{}-{}.wav".format(currenttime[0], currenttime[1]), 'wb') wf.setnchannels(CHANNELS) wf.setsampwidth(p.get_sample_size(FORMAT)) wf.setframerate(RATE) wf.writeframes(b''.join(frames)) wf.close() sleep(intervalSeconds[selected])
from apa102 import APA102 from colorsys import hsv_to_rgb """ This example should display a rainbow scaled across your LEDs. Swap PIN_DAT and PIN_CLK for "Plasma" connector on Picade HAT """ NUM_LEDS = 4 * 4 * 4 FPS = 30 PIN_DAT = 14 PIN_CLK = 15 PIN_SEL = None lights = APA102(NUM_LEDS, PIN_DAT, PIN_CLK, PIN_SEL, brightness=0.5) total = NUM_LEDS // 4 while True: t = time.time() / 2 for p in range(NUM_LEDS): offset = p // 4 r, g, b = [ int(c * 255) for c in hsv_to_rgb(t + offset / total, 1.0, 1.0) ] lights.set_pixel(p, r, g, b) lights.show() time.sleep(1.0 / FPS)
from picovoice import Picovoice from apa102 import APA102 COLORS_RGB = dict( blue=(0, 0, 255), green=(0, 255, 0), orange=(255, 128, 0), pink=(255, 51, 153), purple=(128, 0, 128), red=(255, 0, 0), white=(255, 255, 255), yellow=(255, 255, 51), ) driver = APA102(num_led=12) power = LED(5) power.on() class PicovoiceDemo(Thread): def __init__(self, keyword_path, context_path, porcupine_sensitivity=0.75, rhino_sensitivity=0.25): super(PicovoiceDemo, self).__init__() def inference_callback(inference): return self._inference_callback(inference)
from apa102 import APA102 import sys, time, os import mraa en = mraa.Gpio(3) if os.geteuid()!=0: time.sleep(1) en.dir(mraa.DIR_OUT) en.write(0) device = APA102(12) i=0 while i<12: if sys.argv[1] == 'blue': device.set_pixel(i,0,0,3,100) elif sys.argv[1] == 'green': device.set_pixel(i,0,3,0,100) elif sys.argv[1] == 'red': device.set_pixel(i,3,0,0,100) i+=1 device.show()
# Flask & Flask-RESTful instance variables app = Flask(__name__) # Core Flask app. api = Api(app) # Flask-RESTful extension wrapper # @app.route applies to the core Flask instance (app). # Here we are serving a simple web page. @app.route('/', methods=['GET']) def index(): return render_template('index.html') # APA102 instance and configuration. apa102 = APA102(num_leds=config.APA102_NUM_LEDS, port=config.APA102_PORT, device=config.APA102_DEVICE, bus_speed_hz=config.APA102_BUS_SPEED_HZ) # Set default LED contrast. apa102.set_contrast(config.APA102_DEFAULT_CONTRAST) # APA102 Flask-RESTFul Resource setup and registration. apa102_api.set_apa102(apa102) api.add_resource(apa102_api.StateControl, "/lights") api.add_resource(apa102_api.ColorControl, "/lights/color") api.add_resource(apa102_api.ContrastControl, "/lights/contrast") api.add_resource(apa102_api.ClearControl, "/lights/clear") api.add_resource(apa102_api.AnimationControl, "/lights/animation") # Servo instance and configuration. servo = Servo(servo_gpio=config.SERVO_GPIO,
import time from apa102 import APA102 from colorsys import hsv_to_rgb lights = APA102(120, 5, 6, None, brightness=0.5, invert=True) while True: t = time.time() * 0.1 for x in range(120): h = t + (x / 240.0) r, g, b = [int(c * 255) for c in hsv_to_rgb(h, 1.0, 1.0)] lights.set_pixel(x, r, g, b) lights.show() time.sleep(1.0 / 60)
pattern.append(i) pattern = pattern + [ 0, ] * 20 colors = [] for r in pattern: colors.append((r, 0, 0)) for g in pattern: colors.append((0, g, 0)) for b in pattern: colors.append((0, 0, b)) for w in pattern: colors.append((w, w, w)) lights = APA102(12, force_gpio=False, spi_max_speed_hz=1000000) try: print("Press Ctrl-C to terminate while statement") while True: for i in range(leds_count): lights.set_pixel(i, *colors[i]) lights.show() colors.append(colors.pop(0)) time.sleep(0.02) except KeyboardInterrupt: pass for i in range(leds_count): lights.set_pixel(i, 0, 0, 0) lights.show()
from machine import Pin from apa102 import APA102 clock = Pin(14, Pin.OUT) # set GPIO14 to output to drive the clock data = Pin(13, Pin.OUT) # set GPIO13 to output to drive the data apa = APA102( clock, data, 128) # create APA102 driver on the clock and the data pin for 8 pixels def intensidad(value=128): max_intensidad = 128 value = value % max_intensidad for i in range(max_intensidad): if i <= value: apa[i] = (255, 255, 255, 32) else: apa[i] = (0, 0, 0, 0) apa.write() # write data to all pixels
import machine, neopixel, esp, network, time, math, utime #from generic_dotstar import Apa102DotStar as APA102 from apa102 import APA102 from rgbhsv import rgb2hsv, hsv2rgb NUM_LEDS = 60 clock = machine.Pin(14) data = machine.Pin(13) apa = APA102(clock, data, NUM_LEDS * 2) brightness = 1 colors = [(0, 0, 0, 0), (20, 232, 30, 3), (0, 234, 141, 3), (1, 126, 213, 3), (181, 61, 255, 3), (141, 0, 196, 3), (20, 232, 30, 3)] colors = [(0, 0, 0), (20, 232, 30), (0, 234, 141), (1, 126, 213), (181, 61, 255), (141, 0, 196), (20, 232, 30)] colors = [(141, 0, 196), (181, 61, 255), (1, 126, 213), (0, 234, 141), (20, 232, 30)] for i in range(len(colors)): colors[i] = rgb2hsv(*colors[i]) FILLER = (0, 25, 0, 1) """ grün eisblau stahlblau lilaish dunkellila """ def grad(start, end, steps, brightness):
import time from apa102 import APA102 colors = [(255, 0, 0), (0, 255, 0), (0, 0, 255)] lights = APA102(3, 10, 11, 8) while True: a, b, c = colors lights.set_pixel(0, *a) lights.set_pixel(1, *b) lights.set_pixel(2, *c) lights.show() colors.insert(0, colors.pop(2)) time.sleep(1.0)
from machine import Pin from apa102 import APA102 clock_pin = 12 data_pin = 14 leds_num = 30 clock = Pin(clock_pin, Pin.OUT) data = Pin(data_pin, Pin.OUT) apa = APA102(clock, data, leds_num) color = [(255,0,0,31),(0,255,0,31),(0,0,255,31),(255,255,255,31)] #红、绿、蓝、白 for i in range(0,leds_num): apa[i] = color[i%4] apa.write()
#!/usr/bin/env python3 """Ultra simple sample on how to use the library""" from apa102 import APA102, Pixel import time # Initialize the library and the strip strip = APA102(num_led=80, global_brightness=20, mosi=10, sclk=11, order='rbg') # Turn off all pixels (sometimes a few light up when the strip gets power) strip.clear_strip() # Prepare a few individual pixels through the various APIs. strip[0] = (255, 0, 0) # Red strip[12] = Pixel.BLUE strip[24] = Pixel(red=0xFF, green=0xFF, blue=0xFF, brightness=100) # White strip[36] = (255, 255, 0, 100) # Yellow strip.set_pixel_rgb(40, 0x00FF00) # Green # Copy the buffer to the Strip (i.e. show the prepared pixels) strip.show() # Wait a few Seconds, to check the result time.sleep(20) # Clear the strip and shut down strip.clear_strip() strip.cleanup()
bright -= b_step return next if __name__ == '__main__': parser = argparse.ArgumentParser(description='Display a larson scanner.') parser.add_argument('num_led', type=int, default=80, nargs='?', help='The number of LEDs in the strip') parser.add_argument('mosi', type=int, default=10, nargs='?', help='The pin for SPI MOSI. 10 corresponds to the Raspberry Pi hardware SPI.' ' Set negative for console debug.') parser.add_argument('sclk', type=int, default=11, nargs='?', help='The pin for SPI SCLK. 11 corresponds to the Raspberry Pi hardware SPI.') parser.add_argument('--duration', dest='duration_s', type=float, default=7, help='How long the scanner should run in seconds.') args = parser.parse_args() with APA102(args.num_led, mosi=args.mosi, sclk=args.sclk) as strip: larson1 = create_larson(strip, 0, strip.num_led // 2 - 1) larson2 = create_larson(strip, strip.num_led // 2, strip.num_led - 1) # Run for 10 seconds end_time = time.time() + args.duration_s while time.time() < end_time: strip.blank() larson1() larson2() strip.show() time.sleep(0.008)