Skip to content

Instantly share code, notes, and snippets.

@rxseger
Last active October 6, 2016 02:58
Show Gist options
  • Save rxseger/8cb50ec05c9bd28afe6dcf14081e51d8 to your computer and use it in GitHub Desktop.
Save rxseger/8cb50ec05c9bd28afe6dcf14081e51d8 to your computer and use it in GitHub Desktop.
test magnetic transducer for nightlight
#!/usr/bin/python
# buzz.py - test magnetic transducer for nightlight
import time
import math
import pigpio
pi = pigpio.pi() # sudo pigpiod
# magnetic transducer
BUZZER_BCM = 19 # board pin #35
#BUZZER_FREQUENCY = 2000 # Hz, try: 8000, 4000, 2000 (rated), 1000, 800, 500, 200, 100, 80, 50, 10
BUZZER_FREQUENCY = 10 # Hz
BUZZER_DUTYCYCLE = 255*0.50
BUZZER_DURATION = 0.1 # seconds
def set_buzzer(on):
if on:
pi.set_PWM_frequency(BUZZER_BCM, BUZZER_FREQUENCY)
pi.set_PWM_dutycycle(BUZZER_BCM, BUZZER_DUTYCYCLE)
else:
pi.set_PWM_frequency(BUZZER_BCM, 0)
pi.set_PWM_dutycycle(BUZZER_BCM, 0)
on = True
while True:
set_buzzer(on)
on = not on
time.sleep(0.1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment