![]() ![]() ChangeFrequency() is the frequency of the PWM signal and, hence, the piezo element. If you didn't define pin7 = GPIO.PWM(7, 100) earlier, you would have to change the pin number on every frequency change you make.Īlso read: Raspberry Pi Monitor Not Working? Try These Fixes Using the shortcut form makes it easier to change the pin you're using. Pin7.ChangeFrequency() is actually a shortcut form of GPIO.PWM(7, 100).ChangeFrequency(). Adjusting their parameters lets you play different kinds of notes. The lines of code in between are just a series of pin7.ChangeFrequency() and sleep(1). ![]() If you skip to the bottom part, you find GPIO.output(7, GPIO.LOW), which does the opposite – it turns pin 7 on LOW. The function GPIO.output() takes in two parameters: the pin number and whether you want to set it HIGH or LOW. That pin is working and giving out a PWM signal. GPIO.output(7, GPIO.HIGH) turns pin 7 on HIGH. To do so, you have to keep them indented after while True. Looped commands run on a loop – they repeat as long as you keep the script running. The rest of the time, it doesn't emit anything (or is at 0V). This means that whenever pin 7 is set to HIGH, it emits 3.3V half of the time. Lastly, pin7.start(50) sets pin 7 to PWM (Pulse Width Modulation) mode. This shortens your code so that you can just use pin7 instead of calling GPIO.PWM(7, 100) all the time. Pin7 = GPIO.PWM(7, 100) makes a variable, pin7, that contains the string GPIO.PWM(7, 100). tup(7, GPIO.OUT) tells Python that you're using pin 7 as an output. This naming format differs from board to board, so it can be a bit harder to follow if you're using BCM on a guide. BCM stands for "Broadcom." Instead of physical pin numbers, BCM chooses their Broadcom SOC Channel. ![]() Here, pin 1 is at the top left, pin 2 beside it, pin 3 below pin 1 and so on.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |