Exemple #1
0
def main():
    with Leds() as leds:

        print('Windows Up')
        tuned_servo.min()
        #               blueLED1.blink(.2,.2) # risk of servo burning if kept
        #               blueLED2.blink(.2,.2)
        leds.pattern = Pattern.blink(500)
        leds.update(Leds.rgb_pattern(Color.BLUE))
        time.sleep(5)

        print('Windows Down')
        tuned_servo.max()
        interior.on()
        yellowLED.on()
        leds.pattern = Pattern.breathe(1000)
        leds.update(Leds.rgb_pattern(Color.YELLOW))

        # Fade from yellow to red
        for i in range(32):
            color = Color.blend(Color.RED, Color.YELLOW, i / 32)
            leds.update(Leds.rgb_on(color))
            time.sleep(0.1)


#               leds.update({
#                       1: Leds.Channel(Leds.Channel.PATTERN, 64),
#                       2: Leds.Channel(Leds.Channel.OFF, 128),
#                       3: Leds.Channel(Leds.Channel.ON, 128),
#                       4: Leds.Channel(Leds.Channel.PATTERN, 64),
#               })

        time.sleep(5)
        leds.update(Leds.rgb_off())
        tuned_servo.close()
        yellowLED.close()
        interior.close()
        blueLED2.close()
 def process(self, joy_score):
     if joy_score > 0:
         self._leds.update(
             Leds.rgb_on(Color.blend(JOY_COLOR, SAD_COLOR, joy_score)))
     else:
         self._leds.update(Leds.rgb_off())
Exemple #3
0
def main():
    with Leds() as leds:
        print('RGB: Solid RED for 1 second')
        leds.update(Leds.rgb_on(Color.RED))
        time.sleep(1)

        print('RGB: Solid GREEN for 1 second')
        leds.update(Leds.rgb_on(Color.GREEN))
        time.sleep(1)

        print('RGB: Solid YELLOW for 1 second')
        leds.update(Leds.rgb_on(Color.YELLOW))
        time.sleep(1)

        print('RGB: Solid BLUE for 1 second')
        leds.update(Leds.rgb_on(Color.BLUE))
        time.sleep(1)

        print('RGB: Solid PURPLE for 1 second')
        leds.update(Leds.rgb_on(Color.PURPLE))
        time.sleep(1)

        print('RGB: Solid CYAN for 1 second')
        leds.update(Leds.rgb_on(Color.CYAN))
        time.sleep(1)

        print('RGB: Solid WHITE for 1 second')
        leds.update(Leds.rgb_on(Color.WHITE))
        time.sleep(1)

        print('RGB: Off for 1 second')
        leds.update(Leds.rgb_off())
        time.sleep(1)

        for _ in range(3):
            print('Privacy: On (brightness=default)')
            leds.update(Leds.privacy_on())
            time.sleep(1)
            print('Privacy: Off')
            leds.update(Leds.privacy_off())
            time.sleep(1)

        for _ in range(3):
            print('Privacy: On (brightness=5)')
            leds.update(Leds.privacy_on(5))
            time.sleep(1)
            print('Privacy: Off')
            leds.update(Leds.privacy_off())
            time.sleep(1)

        print('Set blink pattern: period=500ms (2Hz)')
        leds.pattern = Pattern.blink(500)

        print('RGB: Blink RED for 5 seconds')
        leds.update(Leds.rgb_pattern(Color.RED))
        time.sleep(5)

        print('RGB: Blink GREEN for 5 seconds')
        leds.update(Leds.rgb_pattern(Color.GREEN))
        time.sleep(5)

        print('RGB: Blink BLUE for 5 seconds')
        leds.update(Leds.rgb_pattern(Color.BLUE))
        time.sleep(5)

        print('Set breathe pattern: period=1000ms (1Hz)')
        leds.pattern = Pattern.breathe(1000)

        print('RGB: Breathe RED for 5 seconds')
        leds.update(Leds.rgb_pattern(Color.RED))
        time.sleep(5)

        print('RGB: Breathe GREEN for 5 seconds')
        leds.update(Leds.rgb_pattern(Color.GREEN))
        time.sleep(5)

        print('RGB: Breathe BLUE for 5 seconds')
        leds.update(Leds.rgb_pattern(Color.BLUE))
        time.sleep(5)

        print('RGB: Increase RED brightness for 3.2 seconds')
        for i in range(32):
            leds.update(Leds.rgb_on((8 * i, 0, 0)))
            time.sleep(0.1)

        print('RGB: Decrease RED brightness for 3.2 seconds')
        for i in reversed(range(32)):
            leds.update(Leds.rgb_on((8 * i, 0, 0)))
            time.sleep(0.1)

        print('RGB: Blend between GREEN and BLUE for 3.2 seconds')
        for i in range(32):
            color = Color.blend(Color.BLUE, Color.GREEN, i / 32)
            leds.update(Leds.rgb_on(color))
            time.sleep(0.1)

        print('RGB: Off for 1 second')
        leds.update(Leds.rgb_off())
        time.sleep(1)

        print('Privacy: On for 2 seconds')
        with PrivacyLed(leds):
            time.sleep(2)

        print('RGB: Solid GREEN for 2 seconds')
        with RgbLeds(leds, Leds.rgb_on(Color.GREEN)):
            time.sleep(2)

        print('Custom configuration for 5 seconds')
        leds.update({
            1: Leds.Channel(Leds.Channel.PATTERN, 128),  # Red channel
            2: Leds.Channel(Leds.Channel.OFF, 0),  # Green channel
            3: Leds.Channel(Leds.Channel.ON, 128),  # Blue channel
            4: Leds.Channel(Leds.Channel.PATTERN, 64),  # Privacy channel
        })
        time.sleep(5)

        print('Done')
Exemple #4
0
 def led_think(self):
     self.log.info("Change LED to THINK colour")
     self.leds.update(
         Leds.rgb_on(
             Color.blend(colours[self.ledthinkcolour], Color.BLACK,
                         self.ledthinkintensity / 100)))
Exemple #5
0
 def led_listen(self):
     self.log.info("Change LED to LISTEN colour")
     self.leds.update(
         Leds.rgb_on(
             Color.blend(colours[self.ledlistencolour], Color.BLACK,
                         self.ledlistenintensity / 100)))
Exemple #6
0
 def led_idle(self):
     self.log.info("Change LED to IDLE colour")
     self.leds.update(
         Leds.rgb_on(
             Color.blend(colours[self.ledidlecolour], Color.BLACK,
                         self.ledidleintensity / 100)))
Exemple #7
0
def main():
    """Face detection camera inference example."""
    parser = argparse.ArgumentParser()
    parser.add_argument(
        '--num_frames',
        '-n',
        type=int,
        dest='num_frames',
        default=None,
        help='Sets the number of frames to run for, otherwise runs forever.')
    args = parser.parse_args()

    # Forced sensor mode, 1640x1232, full FoV. See:
    # https://picamera.readthedocs.io/en/release-1.13/fov.html#sensor-modes
    # This is the resolution inference run on.
    with PiCamera(sensor_mode=4, resolution=(1640, 1232), framerate=30) as camera,\
                        Leds() as leds:
        leds.update(Leds.privacy_on())
        leds.update(Leds.rgb_on(Color.BLUE))
        camera.start_preview()
        tone_player = TonePlayer(BUZZER_GPIO, bpm=70)
        #tone_player.play(*LOAD_SOUND)

        # Annotator renders in software so use a smaller size and scale results
        # for increased performace.
        annotator = Annotator(camera, dimensions=(320, 240))
        scale_x = 320 / 1640
        scale_y = 240 / 1232

        # Incoming boxes are of the form (x, y, width, height). Scale and
        # transform to the form (x1, y1, x2, y2).
        def transform(bounding_box):
            x, y, width, height = bounding_box
            return (scale_x * x, scale_y * y, scale_x * (x + width),
                    scale_y * (y + height))

        with CameraInference(face_detection.model()) as inference:
            for result in inference.run(args.num_frames):
                faces = face_detection.get_faces(result)
                annotator.clear()
                for face in faces:
                    annotator.bounding_box(transform(face.bounding_box),
                                           fill=0)
                    x, y, width, height = face.bounding_box

                annotator.update()

                if len(faces) >= 1:
                    print(
                        '#%05d (%5.2f fps): num_faces=%d, avg_joy_score=%.2f, x=%.2f, y=%.2f, width=%.2f, height=%.2f'
                        % (inference.count, inference.rate, len(faces),
                           avg_joy_score(faces), x, y, width, height))
                    distance = focal_length * real_face_width_inches / width

                    if x > 0:
                        alpha = x / float(1200)
                        brightness = 254 - (distance * 2)
                    else:
                        alpha = .5
                        brightness = 254
                    try:
                        leds.update(
                            Leds.rgb_on(
                                Color.blend(Color.BLUE, Color.RED, alpha)))
                        b.set_light(2, 'bri', brightness)
                    except:
                        pass
                    camera.annotate_text = '%d inches' % distance
                else:
                    pass

        camera.stop_preview()
Exemple #8
0
def main():
    with Leds() as leds:
        print('RGB: Solid RED for 1 second')
        leds.update(Leds.rgb_on(Color.RED))
        time.sleep(1)

        print('RGB: Solid GREEN for 1 second')
        leds.update(Leds.rgb_on(Color.GREEN))
        time.sleep(1)

        print('RGB: Solid YELLOW for 1 second')
        leds.update(Leds.rgb_on(Color.YELLOW))
        time.sleep(1)

        print('RGB: Solid BLUE for 1 second')
        leds.update(Leds.rgb_on(Color.BLUE))
        time.sleep(1)

        print('RGB: Solid PURPLE for 1 second')
        leds.update(Leds.rgb_on(Color.PURPLE))
        time.sleep(1)

        print('RGB: Solid CYAN for 1 second')
        leds.update(Leds.rgb_on(Color.CYAN))
        time.sleep(1)

        print('RGB: Solid WHITE for 1 second')
        leds.update(Leds.rgb_on(Color.WHITE))
        time.sleep(1)

        print('RGB: Off for 1 second')
        leds.update(Leds.rgb_off())
        time.sleep(1)

        for _ in range(3):
            print('Privacy: On (brightness=default)')
            leds.update(Leds.privacy_on())
            time.sleep(1)
            print('Privacy: Off')
            leds.update(Leds.privacy_off())
            time.sleep(1)

        for _ in range(3):
            print('Privacy: On (brightness=5)')
            leds.update(Leds.privacy_on(5))
            time.sleep(1)
            print('Privacy: Off')
            leds.update(Leds.privacy_off())
            time.sleep(1)

        print('Set blink pattern: period=500ms (2Hz)')
        leds.pattern = Pattern.blink(500)

        print('RGB: Blink RED for 5 seconds')
        leds.update(Leds.rgb_pattern(Color.RED))
        time.sleep(5)

        print('RGB: Blink GREEN for 5 seconds')
        leds.update(Leds.rgb_pattern(Color.GREEN))
        time.sleep(5)

        print('RGB: Blink BLUE for 5 seconds')
        leds.update(Leds.rgb_pattern(Color.BLUE))
        time.sleep(5)

        print('Set breathe pattern: period=1000ms (1Hz)')
        leds.pattern = Pattern.breathe(1000)

        print('RGB: Breathe RED for 5 seconds')
        leds.update(Leds.rgb_pattern(Color.RED))
        time.sleep(5)

        print('RGB: Breathe GREEN for 5 seconds')
        leds.update(Leds.rgb_pattern(Color.GREEN))
        time.sleep(5)

        print('RGB: Breathe BLUE for 5 seconds')
        leds.update(Leds.rgb_pattern(Color.BLUE))
        time.sleep(5)

        print('RGB: Increase RED brightness for 3.2 seconds')
        for i in range(32):
            leds.update(Leds.rgb_on((8 * i, 0, 0)))
            time.sleep(0.1)

        print('RGB: Decrease RED brightness for 3.2 seconds')
        for i in reversed(range(32)):
            leds.update(Leds.rgb_on((8 * i, 0, 0)))
            time.sleep(0.1)

        print('RGB: Blend between GREEN and BLUE for 3.2 seconds')
        for i in range(32):
            color = Color.blend(Color.BLUE, Color.GREEN, i / 32)
            leds.update(Leds.rgb_on(color))
            time.sleep(0.1)

        print('RGB: Off for 1 second')
        leds.update(Leds.rgb_off())
        time.sleep(1)

        print('Privacy: On for 2 seconds')
        with PrivacyLed(leds):
            time.sleep(2)

        print('RGB: Solid GREEN for 2 seconds')
        with RgbLeds(leds, Leds.rgb_on(Color.GREEN)):
            time.sleep(2)

        print('Custom configuration for 5 seconds')
        leds.update({
            1: Leds.Channel(Leds.Channel.PATTERN, 128),  # Red channel
            2: Leds.Channel(Leds.Channel.OFF, 0),        # Green channel
            3: Leds.Channel(Leds.Channel.ON, 128),       # Blue channel
            4: Leds.Channel(Leds.Channel.PATTERN, 64),   # Privacy channel
        })
        time.sleep(5)

        print('Done')
 def process(self, joy_score):
     if joy_score > 0:
         self._leds.update(Leds.rgb_on(Color.blend(JOY_COLOR, SAD_COLOR, joy_score)))
     else:
         self._leds.update(Leds.rgb_off())
Exemple #10
0
#!/usr/bin/env python3

import time
from aiy.leds import (Leds, Color)

with Leds() as leds:
    print('RGB: Blend between PURPLE and BLUE over 3 seconds')
    for i in range(30):
        color = Color.blend(Color.BLUE, Color.PURPLE, i / 30)
        leds.update(Leds.rgb_on(color))
        time.sleep(0.1)

    print('RGB: Blend between GREEN and BLUE over 3 seconds')
    for i in range(30):
        color = Color.blend(Color.BLUE, Color.GREEN, i / 30)
        leds.update(Leds.rgb_on(color))
        time.sleep(0.1)