Exemple #1
0
def send_signal_to_pins(result0, gpio_logic):
    if 'stop' in result0:
        pinStatus(pin_A, 'LOW', gpio_logic)
        pinStatus(pin_B, 'LOW', gpio_logic)
        pinStatus(pin_C, 'LOW', gpio_logic)
        leds.update(Leds.rgb_on(RED))
    elif 'left' in result0:
        pinStatus(pin_A, 'LOW', gpio_logic)
        pinStatus(pin_B, 'LOW', gpio_logic)
        pinStatus(pin_C, 'HIGH', gpio_logic)
        leds.update(Leds.rgb_on(BLUE))
    elif 'right' in result0:
        pinStatus(pin_A, 'LOW', gpio_logic)
        pinStatus(pin_B, 'HIGH', gpio_logic)
        pinStatus(pin_C, 'LOW', gpio_logic)
        leds.update(Leds.rgb_on(PURPLE))
    elif 'slow' in result0:
        pinStatus(pin_A, 'LOW', gpio_logic)
        pinStatus(pin_B, 'HIGH', gpio_logic)
        pinStatus(pin_C, 'HIGH', gpio_logic)
        leds.update(Leds.rgb_on(GREEN))
    else:
        pinStatus(pin_A, 'HIGH', gpio_logic)
        pinStatus(pin_B, 'LOW', gpio_logic)
        pinStatus(pin_C, 'LOW', gpio_logic)
        leds.update(Leds.rgb_off())
    time.sleep(1)
Exemple #2
0
def run():
    if KeepWatchForSeconds(3):
        print("Go test mode")
        leds.update(Leds.rgb_on(BLUE))
        test_mode(test_time=100)
        manual_screen()
        leds.update(Leds.rgb_on(WHITE))

    else:
        print("Beep sound")
        toneplayer.play(*BEEP_SOUND)

        leds.update(Leds.rgb_on(RED))
        print("process")
        gu_servo.max()
        first_gu()
        janken_screen()
        your_hand = hand_recog()
        janken(your_hand)

        print("Done")
        gu_servo.min()
        choki_servo.min()
        pa_servo.min()
        leds.update(Leds.rgb_on(WHITE))
        manual_screen()
Exemple #3
0
def flag():
    for i in range(4):
        with Leds() as leds:
            leds.update(Leds.rgb_on(Color.BLUE))
            sleep(1)

            leds.update(Leds.rgb_on(Color.RED))
            sleep(1)

            leds.update(Leds.rgb_on(Color.WHITE))
            sleep(1)
Exemple #4
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('--filename', '-f', default='recording.wav')
    args = parser.parse_args()

    leds = Leds()
    leds.pattern = Pattern.breathe(4000)
    leds.update(Leds.rgb_on((0, 8, 0)))

    pygame.init()
    pygame.mixer.init()

    mix = alsaaudio.Mixer()
    mix.setvolume(30)

    # Files
    all_files = []
    for (dirpath, dirnames, filenames) in walk('/home/pi/jukidbox_store'):
        all_files.extend([path.join(dirpath, file) for file in filenames])

    while True:
        leds.update(Leds.rgb_on((0, 8, 0)))
        try:
            with Board() as board:
                while True:
                    print('Press button to start.')
                    board.button.wait_for_press()

                    done = threading.Event()
                    board.button.when_pressed = done.set

                    print('Playing...')
                    leds.update(Leds.rgb_pattern(Color.PURPLE))
                    # Get random file
                    file = numpy.random.choice(all_files)
                    print(file)
                    pygame.mixer.music.load(file)
                    pygame.mixer.music.play(-1)

                    while mixer.music.get_busy():
                        if done.is_set():
                            leds.update(Leds.rgb_on((32, 0, 0)))
                            mixer.music.stop()
                        time.sleep(0.5)

                    print("Finished ..")
                    leds.update(Leds.rgb_on((0, 8, 0)))
        except Exception as e:
            print(e)
            leds.update(Leds.rgb_on(Color.YELLOW))
            time.sleep(2)
def run():
    if KeepWatchForSeconds(3):
        print("Going shutdown by GPIO")
        leds.update(Leds.rgb_off())
        os.system("/sbin/shutdown -h now 'Poweroff by GPIO'")

    else:
        print("Beep sound")
        toneplayer.play(*BEEP_SOUND)

        leds.update(Leds.rgb_on(RED))
        print("process")

        print("Done")
        leds.update(Leds.rgb_on(WHITE))
Exemple #6
0
def main():
    logging.basicConfig(level=logging.DEBUG)

    parser = argparse.ArgumentParser(description='Assistant service example.')
    parser.add_argument('--language', default=locale_language())
    args = parser.parse_args()

    logging.info('Initializing for language %s...', args.language)
    hints = get_hints(args.language)
    client = CloudSpeechClient()
    with Board() as board:
        #board.led.state = Led.ON
        with Leds() as leds:
            while True:
                if hints:
                    logging.info('Say something, e.g. %s.' % ', '.join(hints))
                else:
                    logging.info('Say something.')
                text = client.recognize(language_code=args.language,
                                        hint_phrases=hints)
                if text is None:
                    logging.info('You said nothing.')
                    continue

                logging.info('You said: "%s"' % text)
                text = text.lower()
                if 'turn on the light' in text:
                    board.led.state = Led.ON
                elif 'turn off the light' in text:
                    board.led.state = Led.OFF
                elif 'blink the light' in text:
                    board.led.state = Led.BLINK
                elif 'goodbye' in text:
                    break
                elif 'happy' in text:
                    leds.pattern = Pattern.blink(50)
                    color = (255, 255, 0)
                    leds.update(Leds.rgb_pattern(color))
                    audio.play_wav('laugh.wav')
                elif 'creep' in text:
                    leds.pattern = Pattern.breathe(1000)
                    color = (102, 140, 255)
                    leds.update(Leds.rgb_on(color))
                elif 'cheer' in text:
                    leds.pattern = Pattern.blink(5)
                    color = (230, 0, 115)
                    leds.update(Leds.rgb_on(color))
                    audio.play_wav('people-cheering.wav')
Exemple #7
0
 def _run(self):
     while not self._done.is_set():
         joy_score = self._joy_score.value
         if joy_score > 0:
             self._leds.update(Leds.rgb_on(blend(JOY_COLOR, SAD_COLOR, joy_score)))
         else:
             self._leds.update(Leds.rgb_off())
Exemple #8
0
def blink_led(color=RED, period=1, n_blinks=3):
    for blink in range(n_blinks):
        leds.update(Leds.rgb_off())
        sleep(period / 2)
        leds.update(Leds.rgb_on(color))
        sleep(period / 2)
    leds.update(Leds.rgb_off())
Exemple #9
0
def reponse_bouton(est_juste, ecart, action):
    with Leds() as leds:
        if est_juste:
            leds.update(Leds.rgb_on(Color.GREEN)
                        )  # Vert fixe pendant 3 secondes si fréquence atteinte
            time.sleep(3)
            print('Corde accordée')
            tts.say('Corde accordée',
                    lang='fr-FR')  ####### Dire la phrase en plus #######
        else:
            period = 10 * ecart
            leds.pattern = Pattern.blink(
                period)  # donne fréquence de pulsation
            print('Tourner la cheville')
            tts.say('Tourner la cheville',
                    lang='fr-FR')  ####### Dire la phrase #######
            if action == 1:
                leds.update(
                    Leds.rgb_pattern(Color.BLUE)
                )  #Clignotement bleu pour augmenter pendant 5 secondes
                time.sleep(5)
            else:
                leds.update(
                    Leds.rgb_pattern(Color.RED)
                )  #Clignotement rouge pour diminuer pendant 5 secondes
                time.sleep(5)
Exemple #10
0
    def process(self, joy_score):
        if joy_score > 0:
            self._leds.update(
                Leds.rgb_on(blend(JOY_COLOR, SAD_COLOR, joy_score)))

        else:
            self._leds.update(Leds.rgb_off())
def reponse_bouton(
    est_juste, ecart
):  ### réponse donnée par la couleur du bouton et la fréquence du clignotement
    with Leds() as leds:
        if est_juste:
            leds.update(Leds.rgb_on(Color.GREEN)
                        )  # Vert fixe pendant 3 secondes si fréquence atteinte
            time.sleep(3)
            print('Corde accordée')
            tts.say('Corde accordée', lang='fr-FR')
        else:
            period = 10 * abs(ecart)
            leds.pattern = Pattern.blink(
                period)  # donne fréquence de pulsation
            print("TOURNER LA CHEVILLE")
            if ecart > 0:
                tts.say('Tendre la corde', lang='fr-FR')
                leds.update(
                    Leds.rgb_pattern(Color.BLUE)
                )  #Clignotement bleu pour augmenter pendant 5 secondes
                time.sleep(5)

            else:
                tts.say('Détendre la corde', lang='fr-FR')
                leds.update(
                    Leds.rgb_pattern(Color.RED)
                )  #Clignotement rouge pour diminuer pendant 5 secondes
                time.sleep(5)
Exemple #12
0
    def menu(self):
        print('Press Arcade Button to begin photo shoot.' + '\n')
        with Board() as board, Leds() as leds:
            while True:
                # pulse LED to indicate ready state
                leds.pattern = Pattern.blink(1000)
                leds.update(Leds.rgb_pattern(Color.WHITE))
                board.button.wait_for_press()
                startTime = datetime.datetime.now()
                board.led.state = Led.ON
                print('LED is on...')
                # update LED to green indicating shoot is live
                leds.update(Leds.rgb_on((107, 255, 0)))
                self.shoot()
                leds.pattern = Pattern.blink(1000)
                leds.update(Leds.rgb_pattern(Color.WHITE))
                print('Press Arcade Button to start again' + '\n' + 'OR....' +
                      '\n' + 'Press and HOLD the Arcade Button for 5 seconds to quit')
                board.button.wait_for_press()
                pressTime = datetime.datetime.now()
                board.button.wait_for_release()
                releaseTime = datetime.datetime.now()
                board.led.state = Led.OFF
                print('OFF')

                pressDuration = releaseTime - pressTime
                sessionDuration = releaseTime - startTime
                if pressDuration.seconds >= 5:
                    leds.update(Leds.rgb_on(Color.PURPLE))
                    print('Photo booth session ran for ' +
                          str(sessionDuration.seconds) + ' seconds')
                    time.sleep(3)
                    TonePlayer(22).play(*[
                        'D5e',
                        'rq',
                        'C5e',
                        'rq',
                        'Be',
                        'rq',
                        'Be',
                        'C5e',
                        'D5e'
                    ])
                    break
                print('Done')
def run():
    if KeepWatchForSeconds(3):
        print("Going shutdown by GPIO")
        leds.update(Leds.rgb_off())
        os.system("/sbin/shutdown -h now 'Poweroff by GPIO'")

    else:
        print("Beep sound")
        toneplayer.play(*BEEP_SOUND)

        leds.update(Leds.rgb_on(RED))
        print("Taking photo")
        sh.cameraLoad()
        sh.shutter()
        sh.cameraSave()

        print("Done")
        leds.update(Leds.rgb_on(WHITE))
def run():
    print("Beep sound")
    toneplayer.play(*BEEP_SOUND)

    leds.update(Leds.rgb_on(RED))
    print("process")
    gu_servo.max()
    first_gu()
    janken_screen()
    your_hand = hand_recog()
    janken(your_hand)

    print("Done")
    gu_servo.min()
    choki_servo.min()
    pa_servo.min()
    leds.update(Leds.rgb_on(WHITE))
    manual_screen()
Exemple #15
0
 def startup(self):
     with Board() as board, Leds() as leds:
         colors = [Color.RED, Color.YELLOW, Color.GREEN, Color.CYAN,
                   Color.BLUE, Color.PURPLE, Color.BLACK, Color.WHITE]
         board.led.state = Led.ON
         for color in colors:
             leds.update(Leds.rgb_on(color))
             time.sleep(0.25)
         TonePlayer(22).play(*jingleBells(6))
         board.led.state = Led.OFF
Exemple #16
0
def main():
    button.when_pressed = run
    leds.update(Leds.rgb_on(WHITE))

    try:
        while True:
            pass
    except KeyboardInterrupt:
        leds.update(Leds.rgb_off())
        pass
def main():
    button.when_pressed = run
    leds.update(Leds.rgb_on(WHITE))
    manual_screen()

    while True:
        for event in pygame.event.get():
            if event.type == KEYDOWN:
                if event.key == K_ESCAPE:
                    leds.update(Leds.rgb_off())
                    sys.exit()
def main():
    startup()
    print('Press Button start. Press Button to stop camera.'
          + 'Press Button again (or press Ctrl-C) to quit.')

    pressDuration = 0

    with Board() as board, Leds() as leds:
        while True:
            board.button.wait_for_press()
            pressTime = datetime.datetime.now()
            board.led.state = Led.ON
            print('ON')
            print('Running facedetect')
            facedetect()

            leds.update(Leds.rgb_on((107, 255, 0)))

            board.button.wait_for_release()
            releaseTime = datetime.datetime.now()
            board.led.state = Led.OFF
            print('OFF')

            pressDuration = releaseTime - pressTime
            print('Program ran for ' + str(pressDuration.seconds) + ' seconds')
            if pressDuration.seconds >= 5:
                leds.update(Leds.rgb_on(Color.PURPLE))
                time.sleep(3)
                TonePlayer(22).play(*[
                    'D5e',
                    'rq',
                    'C5e',
                    'rq',
                    'Be',
                    'rq',
                    'Be',
                    'C5e',
                    'D5e'
                ])
                break
            print('Done')
Exemple #19
0
def send_signal_to_servos(result0):
    if 'stop' in result0:
        tuned_servoA.value = 0.5
        tuned_servoB.value = 0.5
        leds.update(Leds.rgb_on(RED))
    elif 'left' in result0:
        tuned_servoA.min()
        tuned_servoB.min()
        leds.update(Leds.rgb_on(BLUE))
    elif 'right' in result0:
        tuned_servoA.max()
        tuned_servoB.max()
        leds.update(Leds.rgb_on(PURPLE))
    elif 'slow' in result0:
        tuned_servoA.value = 0.6
        tuned_servoB.value = 0.3
        leds.update(Leds.rgb_on(GREEN))
    else:
        tuned_servoA.max()
        tuned_servoB.min()
        leds.update(Leds.rgb_off())
    time.sleep(0.002)
Exemple #20
0
def run():
    if KeepWatchForSeconds(3):
        print("Going shutdown by GPIO")
        leds.update(Leds.rgb_off())
        os.system("/sbin/shutdown -h now 'Poweroff by GPIO'")

    else:
        print("Beep sound")
        toneplayer.play(*BEEP_SOUND)

        leds.update(Leds.rgb_on(RED))
        print("Taking photo")
        with picamera.PiCamera() as camera:
            camera.resolution = (640, 480)
            camera.start_preview()
            sleep(3.000)
            camera.capture(photo_filename)

        leds.update(Leds.rgb_on(GREEN))
        print("Dish classifier")
        with ImageInference(dish_classification.model()) as inference:
            image = Image.open(photo_filename)
            classes = dish_classification.get_classes(
                inference.run(image),
                max_num_objects=5,
                object_prob_threshold=0.1)
            dish_name = ''
            for i, (label, score) in enumerate(classes):
                dish_name += label + '/'
                print('Result %d: %s (prob=%f)' % (i, label, score))

        leds.update(Leds.rgb_on(BLUE))
        print("Post to slack")
        slack.files.upload(photo_filename,
                           channels='#food_diary',
                           title=dish_name)

        leds.update(Leds.rgb_on(WHITE))
def startup():
    with Board() as board, Leds() as leds:
        colors = [Color.RED, Color.YELLOW, Color.GREEN, Color.CYAN,
                  Color.BLUE, Color.PURPLE, Color.BLACK, Color.WHITE]
        board.led.state = Led.ON
        for color in colors:
            leds.update(Leds.rgb_on(color))
            time.sleep(0.5)
        TonePlayer(22).play(*[
            'Be',
            'rs',
            'C5e',
            'rs',
            'D5e',
        ])
        board.led.state = Led.OFF
Exemple #22
0
def loop(inference, robot, annotator, leds):
    for inference_result in inference.run(None):

        # Get all the faces.
        faces = face_detection.get_faces(inference_result)

        # Get the stronger face.
        stronger_face = selectFaceWithHigherScore(faces)

        if stronger_face is None:
            print("No face detected")
            continue

        # Angular difference between the face and the center of the camera.
        face_x_center = stronger_face.bounding_box[
            0] + stronger_face.bounding_box[2] / 2
        face_y_center = stronger_face.bounding_box[
            1] + stronger_face.bounding_box[3] / 2

        face_x_normalized = face_x_center / CAMERA_WIDTH
        face_y_normalized = face_y_center / CAMERA_HEIGHT

        face_x_angle = (face_x_normalized * 2 - 1) * (CAMERA_FOV_WIDTH / 2)
        # The screen and motor axis are reversed.
        face_y_angle = -(face_y_normalized * 2 - 1) * (CAMERA_FOV_HEIGHT / 2)

        print("Face delta: %s %s" % (face_x_angle, face_y_angle))
        robot.deltaYaw(controller(face_x_angle))
        robot.deltaPitch(controller(face_y_angle))

        leds.update(
            Leds.rgb_on((255 * (1 - stronger_face.joy_score),
                         255 * stronger_face.joy_score, 0)))

        if SLEEP > 0:
            sleep(SLEEP)

        if PRINT_LOGS:
            for face_idx, face in enumerate(faces):
                print("Face %i -> %s" % (face_idx, face))

        if ENABLE_DISPLAY:
            annotator.clear()
            for face in faces:
                annotator.bounding_box(transform_annotator(face.bounding_box),
                                       fill=0)
            annotator.update()
Exemple #23
0
def main():
    print("Play tune")
    player = TonePlayer(gpio=BUZZER_GPIO_PIN, bpm=10)
    player.play(*START_SOUND)

    print("Initialize robot")
    robot = Robot()
    robot.resetPosition()

    print("Switch on leds")
    with Leds() as leds:
        leds.update(Leds.rgb_on(Color.GREEN))

        print("Switch on camera")
        with PiCamera(sensor_mode=4,
                      resolution=(CAMERA_WIDTH, CAMERA_HEIGHT),
                      framerate=30) as camera:

            if ENABLE_DISPLAY:
                camera.start_preview()
                annotator = Annotator(camera, dimensions=(320, 240))
            else:
                annotator = None

            print("Load model")
            with CameraInference(face_detection.model()) as inference:

                loop(inference=inference,
                     robot=robot,
                     annotator=annotator,
                     leds=leds)

            if ENABLE_DISPLAY:
                camera.stop_preview()

    player.play(*STOP_SOUND)

    # Give time for the user to remote its finger.
    sleep(3)
    robot.resetPosition()
Exemple #24
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()
Exemple #25
0
def main():
    with Board() as board:
        with Leds() as leds:
            # init volume and brightness
            set_volume(0)
            leds.pattern = Pattern.breathe(750)
            leds.update(Leds.rgb_pattern(Color.BLACK))

            done = threading.Event()
            board.button.when_pressed = done.set

            alarm_thread = threading.Thread(target=alarm,
                                            args=(done, leds),
                                            daemon=True)
            alarm_thread.start()

            if done.wait(timeout=TIMEOUT_LIMIT):
                set_volume(MAX_VOLUME)
                leds.update(Leds.rgb_on(Color.GREEN))
                print('GOOD MORNING!')
                play_wav(GOOD_MORNING_SOUND_PATH)
            else:
                print('Timed out.')
Exemple #26
0
def main():
    parser = argparse.ArgumentParser(
        'Image classification camera inference example.')
    parser.add_argument(
        '--num_frames',
        '-n',
        type=int,
        default=None,
        help='Sets the number of frames to run for, otherwise runs forever.')
    parser.add_argument('--num_objects',
                        '-c',
                        type=int,
                        default=3,
                        help='Sets the number of object interences to print.')
    parser.add_argument('--nopreview',
                        dest='preview',
                        action='store_false',
                        default=True,
                        help='Enable camera preview')
    args = parser.parse_args()

    with Leds() as leds:
        with PiCamera(sensor_mode=4, framerate=30) as camera, \
             CameraPreview(camera, enabled=args.preview), \
             CameraInference(image_classification.model()) as inference:
            for result in inference.run(args.num_frames):
                classes = image_classification.get_classes(
                    result, top_k=args.num_objects)
                print(classes_info(classes))
                #print("my class: "+classes[0][0])
                if classes:
                    camera.annotate_text = '%s (%.2f)' % classes[0]
                    if "mouse" in str(classes[0][0]):
                        leds.update(Leds.rgb_on(Color.RED))
                    else:
                        leds.update(Leds.rgb_off())
PURPLE = (0xFF, 0x00, 0xFF)
CYAN = (0x00, 0xFF, 0xFF)
WHITE = (0xFF, 0xFF, 0xFF)


def blend(color_a, color_b, alpha):
    return tuple([
        math.ceil(alpha * color_a[i] + (1.0 - alpha) * color_b[i])
        for i in range(3)
    ])


leds = Leds()

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

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

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

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

print('RGB: Solid PURPLE for 1 second')
def _setColor(color):
    global state
    if(state):
        Leds().update(Leds.rgb_on(color))
Exemple #29
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 #30
0
    for i in range(X.shape[0]):
        window = X[i].reshape(1, 1, X.shape[2], X.shape[1])
        #print(window.shape)
        detectionNet.setInput(window)
        #    local_results.append(model.predict(window))
        local_results.append(detectionNet.forward())

# Aggregate predictions for file into one then append to all_results
    local_results = (np.sum(np.array(local_results), axis=0) /
                     len(local_results))[0]
    local_results = list(local_results)
    print(local_results)
    prediction = np.argmax(local_results)
    print(classes[prediction])
    print(led_dict.get(classes[prediction]))
    leds.update(Leds.rgb_on(led_dict.get(classes[prediction])))
    print(wav.shape)
    resampled_wav = librosa.resample(wav, 48000, 16000)
    #concated_wav = np.concatenate((resampled_wav, resampled_wav), axis=0)
    print(resampled_wav.shape)
    #print(concated_wav.shape)
    spec = get_fft_spectrum(resampled_wav)
    print(spec.shape)
    #for index, row in df.iterrows():
    #print(row['c1'], row['c2'])
    enroll_embs = np.array([emb.tolist() for emb in df['embedding']])
    spec = spec.astype('float32')
    spec_reshaped = spec.reshape(1, 1, spec.shape[0], spec.shape[1])
    srNet.setInput(spec_reshaped)
    pred = srNet.forward()
    emb = np.squeeze(pred)
 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 #32
0
import time
from aiy.leds import Leds, Color, Pattern


with Leds() as leds:
    for _ in range(4):
        leds.update(Leds.privacy_on())
        leds.update(Leds.rgb_on(Color.GREEN))
        time.sleep(1)
        leds.update(Leds.rgb_off())
        time.sleep(1)
        leds.update(Leds.rgb_on(Color.GREEN))
        time.sleep(1)
        leds.update(Leds.rgb_off())
        time.sleep(1)
        leds.update(Leds.privacy_off())

with Leds() as leds:
    leds.pattern = Pattern.blink(500)
    leds.update(Leds.rgb_pattern(Color.GREEN))
    time.sleep(5)