I'm trying to have a buzzer sound and an LED light blink at the same time with independent duty cycles, and frequency. I tried to do this with two different pins, but it seems to glitch (buzzer crackling and LED visually crackling)
Code: Select all
#!/usr/bin/env python
import RPi.GPIO as GPIO
import time
from multiprocessing import Process
def setup():
global BuzzerPin
global LEDPin
BuzzerPin = 11 #BCM17 GPIO17
LEDPin = 12 #BCM18 GPIO18 Controlling transistor
GPIO.setmode(GPIO.BOARD) # Numbers GPIOs by physical location
#Buzzer Setup
GPIO.setup(BuzzerPin, GPIO.OUT)
GPIO.output(BuzzerPin, GPIO.LOW)
#LED Setup
GPIO.setup(LEDPin, GPIO.OUT)
GPIO.output(LEDPin, GPIO.LOW)
def beep():
for y in range(3):
GPIO.output(BuzzerPin, GPIO.HIGH)
time.sleep(1)
GPIO.output(BuzzerPin, GPIO.LOW)
time.sleep(1)
time.sleep(1.5)
def light():
for y in range(10):
GPIO.output(LEDPin, GPIO.HIGH)
time.sleep(0.25)
GPIO.output(LEDPin, GPIO.LOW)
def loop():
while True:
buzzer = Process(target=beep)
buzzer.start()
LED = Process(target= light)
LED.start()
def destroy():
GPIO.output(BuzzerPin, GPIO.HIGH)
GPIO.cleanup() # Release resource
if __name__ == '__main__': # Program start from here
setup()
try:
loop()
except KeyboardInterrupt: # When 'Ctrl+C' is pressed, the child program destroy() will be executed.
destroy()How do I get an LED light to blink (continuous beacon-like) and a buzzer to beep (fire alarm style ) simultaneously?