CircuitPython School - The Right Way to Add Buttons to a Raspberry Pi, Pinouts, and Cheer Machine
ฝัง
- เผยแพร่เมื่อ 8 ก.พ. 2025
- We add a button to the Raspberry Pi, then add the adafruit_debouncer CircuitPython library to our Pi, and write code to make sure we only respond to a single press at a time. We also identify Raspberry Pi pinouts using pinout.xyz, and we learn to use PyGame to play sounds and music, identifgy when sounds are playing, and stop a playing sound. Part of Prof. John Gallaugher's Physical Computing course.
Well Done Prof..
Hi. Thanks for the tutorials. I note that the sound seems to play when the button is released. I'd like to have the action when it's initially pressed in my application. Any suggestions?
Check out the other button tutorials in bit.ly/circuitpython-tutorials. You’ll find ideas and techniques there. Hack on!
Very informative videos. Thank you. I am trying to create a python program on a newly purchased Raspberry Pi 4. I want to put the Pi in a pedal car with LED lights in the exhaust. (8 of them) I have a potentiometer that the user can press to make the LEDs flash at 6 different rates as they press the pedal. This all works well but I would like to add sound also. That means when you press the pedal, I want the LED to change speed and the sound to either get louder or faster. I can't seem to get the LED flashing at the same time sound plays. Is there some code that will achieve this? Thank you in advance. Jeff
Check in the course playlist. You’ll see various techniques that I teach my students in the bit.ly/circuitpython-tutorials list. Good luck!
Student asked if you can use fStrings for this. Absolutely (always try it out). It'd be like this:
pygame.mixer.music.load(path + f"sound{sound_number}.mp3")
is f`string a way to make the chosen sound file at random? (Im looking for such a funktion)
when i try to make it i get a import error : no module named board, is there a way I can fix this?
Sounds like you need to go through the earlier video in the playlist to install CircuitPython and Blinka. When you get a no such module it means that the library you are using (board in this case) was not installed on your computer (which is the case I’d you haven’t set up blinka) or you baked the module wrong (eg it’s not spelled properly with same all lowercase lettering). Good luck!
Nice video, thanks for creating. Why would someone use debouncer over RPi.GPIO for buttons?
The reason I ask is because debouncer is no longer compatible with Python versions less than 3.8. As a result I switched my Raspberry Pi from Python 3.7 to Python 3.12 but now one of the libraries I use (openAI) has an issue with Python 3.12. While the OpenAI devs fix their issue with Python 3.12, I could have just switched Pi to Python 3.8-3.11instead but opted to just use RPi.GPIO instead.
how can we add mutiple buttoons ? with
button1 = digitalio.DigitalInOut(board.D5)
button1.switch_to_input(pull=digitalio.Pull.UP)
button1 = Debouncer(button1)
and more or there is an other solution ?
Thanks
Just crear different buttons with different names and pins. Be careful. The code you list shows button1 used in all three lines. That last line that passes a configuration into Debouncer needs to have a different name on the left of the equal sign. Look at the code for a good naming template to use. Good luck!
@@profgallaugher Thanks you :)
hallo.
how can i make piano with raspberry pi
Check out the full playlist for ideas and all playlists on the channel.
Круто!