Page 336 - 3-2
P. 336

recognize_stream.cancel()
                        return info


                    except grpc.RpcError as e:
                        code = e.code()
                        # CANCELLED is caused by the interrupt handler, which is expected.
                        if code is not code.CANCELLED:
                            raise
            ###################################################
            # sensor.py
            # -*- coding: utf-8 -*-
            import RPi.GPIO as GPIO
            import time
            import pygame
            import sys


            GPIO.setmode(GPIO.BCM)
            GPIO.setup(18, GPIO.IN)


            def sensor_start():
                while 1:
                    if GPIO.input(18):
                        print(" 센서 인식")
                        pygame.mixer.init()
                        pygame.mixer.music.load("0.mp3") # "  수동 버튼이나 음성 인식 버튼을 눌러주세요."
                        pygame.mixer.music.play()
                        time.sleep(4)
                        break
                    else:
                        print (" 센서 X")


                    time.sleep(0.5)
            ###############################################################
            # one_serial_voice.py
            # -*- coding: utf-8 -*-
            import pygame                    # pygame   모듈을 import
            from pygame.locals import *      # pygame.locals  하위 모듈을 import
            import sys
            import time
            import os
            import serial                  # 시리얼 통신 모듈 import


            #==============   시리얼 통신부============
            # serial bps 9600
            ser = serial.Serial('/dev/ttyS0', 9600, timeout=1)


                                                         - 336 -
   331   332   333   334   335   336   337   338   339   340   341