Up テスト 作成: 2021-03-28
更新: 2021-03-28


    配線


    テストに使用するプログラム
     ──音を検知したら,LED が点灯
#!/usr/bin/python import RPi.GPIO as GPIO SoundPin = 18 LedPin = 16 def setup(): # Set the GPIO pins as numbering GPIO.setmode(GPIO.BOARD) # Set the SoundPin's mode is input, and (Not detected→) ON→ LOW GPIO.setup(SoundPin, GPIO.IN, pull_up_down=GPIO.PUD_UP) # Set the LedPin's mode is output GPIO.setup(LedPin,GPIO.OUT) # Set the LedPin low GPIO.output(LedPin, GPIO.LOW) def destroy(): # Release resource GPIO.cleanup() def loop(): while True: if GPIO.input(SoundPin) == GPIO.HIGH: GPIO.output(LedPin,GPIO.HIGH) else: GPIO.output(LedPin,GPIO.LOW) # The Program will start from here if __name__ == '__main__': setup() try: loop() # When control c is pressed child program destroy() will be executed. except KeyboardInterrupt: destroy()


    $ vi ky_038.py

    $ chmod +x ky_038.py

    $ ./ky_038.py