コード例 #1
0
    def start(self):
        """This method does the actual work."""
        try:
            strip = apa102.APA102(
                num_led=self.num_led,
                global_brightness=self.global_brightness,
                mosi=self.mosi,
                sclk=self.sclk,
                order=self.order,
                max_speed_hz=15000000)  # Initialize the strip
            strip.clear_strip()
            self.init(strip, self.num_led)  # Call the subclasses init method
            strip.show()
            current_cycle = 0
            while True:  # Loop forever
                for current_step in range(self.num_steps_per_cycle):
                    need_repaint = self.update(strip, self.num_led,
                                               self.num_steps_per_cycle,
                                               current_step, current_cycle)
                    if need_repaint:
                        strip.show()  # repaint if required
                    time.sleep(self.pause_value)  # Pause until the next step
                current_cycle += 1
                if self.num_cycles != -1:
                    if current_cycle >= self.num_cycles:
                        break
            # Finished, cleanup everything
            self.cleanup(strip)

        except KeyboardInterrupt:  # Ctrl-C can halt the light program
            print('Interrupted...')
            self.cleanup(strip)
コード例 #2
0
 def __init__(self, breedte, hoogte):
     self.breedte = breedte
     self.hoogte = hoogte
     # Initialize the library and the strip
     self.strip = apa102.APA102(num_led=(breedte * hoogte),
                                global_brightness=31,
                                mosi=10,
                                sclk=11,
                                order='rgb')
コード例 #3
0
    def start(self):
        """This method does the actual work."""
        try:
            strip = apa102.APA102(num_led=self.num_led,
                                  global_brightness=self.global_brightness,
                                  mosi = self.mosi, sclk = self.sclk,
                                  order=self.order) # Initialize the strip
            strip.clear_strip()
            self.init(strip, self.num_led) # Call the subclasses init method
            strip.show()
            current_cycle = 0

            print('initialize, go!')
            while True:  # Loop forever
              self.setAll(strip,0xFF0000)
              time.sleep(0.3)
              self.setAll(strip,0x00FF00)
              time.sleep(0.3)
              self.setAll(strip,0x0000FF)
              time.sleep(0.3)
              print('next')
              continue


            #strip.set_pixel_rgb(0, 0x0000FF,20)
             # strip.set_pixel_rgb(1, 0xFF0000,20)


              #time.sleep(1)
              #with open('/run/sensors/scd30/last', 'r') as content_file:
              #  content = content_file.read()
              #  dataarray = content.splitlines()
              #  for i in dataarray:
                  #if re.search(r'gas="CO2"', i):
                    # value = float(i.split()[1])
              """

              value = 400
              if(value < 800):
                strip.set_pixel_rgb(0, 0x0000FF,20)
                strip.set_pixel_rgb(1, 0x0000FF,20)
              elif(value < 1500):
                strip.set_pixel_rgb(0, 0xFF00AA,20)
                strip.set_pixel_rgb(1, 0xFF00AA,20)
              else:
                strip.set_pixel_rgb(0, 0xFF0000,20)
                strip.set_pixel_rgb(1, 0xFF0000,20)
              """
  
              



        except KeyboardInterrupt:  # Ctrl-C can halt the light program
            print('Interrupted...')
            self.cleanup(strip)
コード例 #4
0
 def __init__(self):
     self.strip = apa102.APA102(num_led=NUM_LED,
                                mosi=MOSI,
                                sclk=SCLK,
                                order='rgb')
     self.strip.clear_strip()
     try:
         self.rainbow()
     except:
         self.shutdown()
コード例 #5
0
 def __init__(self, num_led, pause_value = 0, num_steps_per_cycle = 100,
              num_cycles = -1, global_brightness = 255, order = 'rgb',
              mosi = 10, sclk = 11):
     self.num_led = num_led # The number of LEDs in the strip
     self.pause_value = pause_value # How long to pause between two runs
     self.num_steps_per_cycle = num_steps_per_cycle # Steps in one cycle.
     self.num_cycles = num_cycles # How many times will the program run
     self.global_brightness = global_brightness # Brightness of the strip
     self.order = order # Strip colour ordering
     self.mosi = mosi # Master out slave in of the SPI protocol
     self.sclk = sclk # Clock line of the SPI protocol
     self.strip = apa102.APA102(num_led=self.num_led,
                           global_brightness=self.global_brightness,
                           mosi = self.mosi, sclk = self.sclk,
                           order=self.order) # Initialize the strip
コード例 #6
0
def _init_visualizer(dev_mode, n_pixels, base_color):
    if dev_mode:
        from virtual_led_strip import VirtualLEDStrip
        visualization_device = VirtualLEDStrip()
    else:
        from driver import apa102
        visualization_device = apa102.APA102(num_led=n_pixels,
                                             global_brightness=23,
                                             mosi=10,
                                             sclk=11,
                                             order='rgb')

    visualizer = LoudnessLengthEdgeFadeVisualizer(visualization_device,
                                                  n_pixels, base_color)
    loading_animator = LoadingAnimator(visualization_device, n_pixels)
    return (visualizer, loading_animator)
コード例 #7
0
 def __init__(self, numleds, mosi, clk):
     threading.Thread.__init__(self)
     self.numleds = numleds
     self.mosi = mosi
     self.clk = clk
     self.strip = apa102.APA102(num_led=self.numleds,
                                global_brightness=BRIGHTNESS,
                                mosi=self.mosi,
                                sclk=self.clk,
                                order='rgb')
     self.state = "solid"
     self.speed = 10
     self.color = 0xff0000
     self.running = True
     self.waitForEvent = threading.Event()
     # Turn off all pixels (sometimes a few light up when the strip gets power)
     self.strip.clear_strip()
コード例 #8
0
    def start(self):
        """This method does the actual work."""
        try:
            strip = apa102.APA102(num_led=self.num_led,
                                  global_brightness=self.global_brightness,
                                  mosi = self.mosi, sclk = self.sclk,
                                  order=self.order) # Initialize the strip
            strip.clear_strip()
            self.init(strip, self.num_led) # Call the subclasses init method
            strip.show()
            current_cycle = 0

            hertz = 40
            initial_wait = self.calcWait(hertz)

            wait = initial_wait
            print('initialize, go!')
            while True:  # Loop forever
              time_before_setting_strip = time.time()
              self.setAll(strip,0xFFFFFF)
              time_after_setting_strip = time.time()
              delta = time_after_setting_strip - time_before_setting_strip
              wait = initial_wait - delta
              if(wait > 0):
                time.sleep(wait)
              else:
                print('setting strip took ' + str(delta) + 's, longer than ' + str(initial_wait) + 's')

              time_before_setting_strip = time.time()
              self.setAll(strip,0x000000)
              time_after_setting_strip = time.time()
              delta = time_after_setting_strip - time_before_setting_strip
              wait = initial_wait - delta
              if(wait > 0):
                time.sleep(wait)
              else:
                print('setting strip took ' + str(delta) + 's, longer than ' + str(initial_wait) + 's')
              continue




        except KeyboardInterrupt:  # Ctrl-C can halt the light program
            print('Interrupted...')
            self.cleanup(strip)
コード例 #9
0
ファイル: wakeuplight.py プロジェクト: remmelt/wakeuplight
def glow_state(strip, state, color, brightness):
    for i in range(0, NUM_LEDS):
        if not i in state:
            strip.set_pixel_rgb(i, color, bright_percent=brightness)
    strip.show()


def random_stars(strip, color, brightness):
    state = list(range(0, NUM_LEDS))
    while len(state) > 0:
        state.remove(choice(state))
        glow_state(strip, state, color, brightness)
        sleep(SLEEP_BETWEEN_STARS)


strip = apa102.APA102(num_led=NUM_LEDS, order=ORDER)
strip.clear_strip()

random_stars(strip, 0x010000, 1)
sleep(SLEEP_BETWEEN_CYCLES)

for color in STAR_COLORS:
    print(color)
    random_stars(strip, color, BRIGHTNESS)
    sleep(SLEEP_BETWEEN_CYCLES)

for brightness in [20, 30, 40, 50, 80, 100]:
    print(brightness)
    random_stars(strip, STAR_COLORS[-1], brightness)
sleep(SLEEP_BETWEEN_CYCLES)
コード例 #10
0
# force shadow client to use offline publish queueing
# overriding the default behaviour for shadow clients in the SDK
MQTTClient = myAWSIoTMQTTShadowClient.getMQTTConnection()
MQTTClient.configureOfflinePublishQueueing(-1)

# Connect to AWS IoT with a 300 second keepalive
myAWSIoTMQTTShadowClient.connect(300)

# Create a deviceShadow with persistent subscription
Bot = myAWSIoTMQTTShadowClient.createShadowHandlerWithName(thingname, True)

# create new instance of shadowCallbackContainer class
shadowCallbackContainer_Bot = shadowCallbackContainer(Bot)

# initialise LED strip, uses SPI pins (BCM10 and BCM11) by default
ledstrip = apa102.APA102(num_led=146)
ledstrip.clear_strip()

# set status, and clear any desired state
shadowCallbackContainer_Bot.statusPost('STARTING')
shadowCallbackContainer_Bot.statusPost('RUNNING')

# register AWSIoT callback to allow remote triggering and configuration
Bot.shadowRegisterDeltaCallback(
    shadowCallbackContainer_Bot.customShadowCallback_Delta)

# loop forever
while True:

    # if sequence 100 then cancel
    if btnTrigger == 100:
コード例 #11
0
#!/usr/bin/env python3
"""Ultra simple sample on how to use the library"""
from driver import apa102
import time

color = 0xFF0000
# Initialize the library and the strip
strip = apa102.APA102(num_led=256,
                      global_brightness=10,
                      mosi=10,
                      sclk=11,
                      order='rbg',
                      max_speed_hz=900000)

# Turn off all pixels (sometimes a few light up when the strip gets power)
strip.clear_strip()

# Prepare a few individual pixels
for pix in range(256):
    for aantal in range(pix, pix + 3):
        strip.set_pixel_rgb(aantal, color)
    strip.show()
    time.sleep(0.05)
    strip.set_pixel_rgb(aantal, 0x000000)
#strip.set_pixel_rgb(12, 0xFF0000) # Red
#strip.set_pixel_rgb(24, 0xFFFFFF) # White
#strip.set_pixel_rgb(40, 0x00FF00) # Green
#print(strip)
# Copy the buffer to the Strip (i.e. show the prepared pixels)
#strip.show()
コード例 #12
0
#!/usr/bin/env python3
"""Ultra simple sample on how to use the library"""
from driver import apa102
import time

# Initialize the library and the strip
strip = apa102.APA102(num_led=256,
                      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
strip.set_pixel_rgb(12, 0xFF0000)  # Red
strip.set_pixel_rgb(24, 0xFFFFFF)  # White
strip.set_pixel_rgb(250, 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()
コード例 #13
0
    import signal
    import sys

    # Will turn all leds off when invoked.
    def signal_handler(signal, frame):
        strip.clear_strip()
        strip.cleanup()
        sys.exit(0)

    # Create a listener that turns the leds off when the program terminates
    signal.signal(signal.SIGTERM, signal_handler)
    signal.signal(signal.SIGINT, signal_handler)

    strip = apa102.APA102(num_led=config.N_PIXELS,
                          global_brightness=config.BRIGHTNESS,
                          mosi=config.LED_MOSI_PIN,
                          sclk=config.LED_SCLK_PIN,
                          order=config.LED_COLOR_ORDER)
    # Turn off all pixels (sometimes a few light up when the strip gets power)
    strip.clear_strip()

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)