I have a multiple choice question game, and I'm wondering how to hook up a piezo buzzer to make a sound when someone puts in an answer.
Basically, I need two functions - a sound for when they get it right, and a sound for when they get it wrong.
I have been unable to find how you set the frequency of a buzzer using GPIO pins.
I tried GPIOzero, but it appears that there aren't any ways to set the frequency. (Please tell me if there are)
I have now tried RPi.GPIO, but my code isn't working - no noise is being made.
I'm sorry as I'm very new to this - and I don't really have any clue what I'm doing.
Here's my current code:
import RPi.GPIO as GPIO from time import sleep GPIO.setmode(GPIO.BOARD) GPIO.setup(26, GPIO.OUT) p = GPIO.PWM(26, 100) def Blink(): for x in range(0,20): GPIO.output(26, True) p.start(100) p.ChangeDutyCycle(90) p.ChangeFrequency(400) sleep(2) p.stop() GPIO.cleanup() Blink()