Skip to content

Instantly share code, notes, and snippets.

@actuino
Created March 31, 2017 20:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save actuino/d88061db0ec118d8de2b6f9d0d84d1d6 to your computer and use it in GitHub Desktop.
Save actuino/d88061db0ec118d8de2b6f9d0d84d1d6 to your computer and use it in GitHub Desktop.
Raspberry Pi Zero Active Buzzer Test
#!/usr/bin/env python
import RPi.GPIO as GPIO
import time
Buzzer = 40 # La pin Buzzer (N° de broche du Raspberry, pas le N° GPIO du proc)
def setup(pin):
global BuzzerPin
BuzzerPin = pin
GPIO.setmode(GPIO.BOARD) # Numbers GPIOs by physical location
GPIO.setup(BuzzerPin, GPIO.OUT)
GPIO.output(BuzzerPin, GPIO.HIGH)
def on():
GPIO.output(BuzzerPin, GPIO.HIGH)
def off():
GPIO.output(BuzzerPin, GPIO.LOW)
def beep(x):
on()
time.sleep(x)
off()
def loop():
while True:
beep(0.03)
time.sleep(0.05)
beep(0.03)
time.sleep(1)
def destroy():
GPIO.output(BuzzerPin, GPIO.HIGH)
GPIO.cleanup() # Release resource
if __name__ == '__main__': # Program start from here
setup(Buzzer)
try:
loop()
except KeyboardInterrupt: # When 'Ctrl+C' is pressed, the child program destroy() will be executed.
destroy()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment