このブログを検索

2016/07/17

raspberry piでブザーを鳴らす

参考:
http://feijoa.jp/laboratory/raspberrypi/speaker/


pi@raspberrypi:~ $ cat buzz2.py
# -*- coding: utf-8 -*-
import RPi.GPIO as GPIO
from time import sleep
import wiringpi2 as wiringpi


outpin = 25

GPIO.setmode(GPIO.BCM)
GPIO.setup(outpin, GPIO.OUT)

wiringpi.wiringPiSetupGpio() # GPIO名で番号を指定する

wiringpi.softToneCreate(outpin)


len=1
delay = 0.1

A1 = 110
A2 = 220
A3 = 440


def Playnote(note,len,delay):
        wiringpi.softToneWrite(outpin, note)
        sleep(len)
        wiringpi.softToneWrite(outpin, 0)
        sleep(delay)

Playnote(A1,len,delay)
Playnote(A2,len,delay)
Playnote(A3,len,delay)

GPIO.cleanup()