Raspberry Pi LESSON 12: Pushbutton Control of RGB LED

  Рет қаралды 10,427

Paul McWhorter

Paul McWhorter

Күн бұрын

Announcing the Most Awesome Raspberry Pi Lessons of All Times! This time we RUMBLE!
In this class series, we will be using the most excellent Sunfounder Ultimate Raspberry Pi kit, available here: (Affiliate Link)
amzn.to/3tSk9Mo
or for our UK friends, amzn.to/3I5d401
In this lesson I will show how to control an RGB LED using three pushbuttons. One will control Red, one Green and One Blue. The buttons are used as toggles to turn the individual colors on and off.
If you want to grab those cool little straight jumper wires I am using to keep my breadboard builds neat and clean you can snag a box of them here:
amzn.to/36NyfHq
If you guys are interested in the oscilloscope I am using, you can pick one up here (affiliate link):
amzn.to/3v13Mhl
You guys get your hardware ordered so you can follow along at home!
You will also need a Raspberry Pi. I suggest the Raspberry Pi 4. If you do not already have one, this is the most suitable gear I could find:
amzn.to/3pBMfKm
The Raspberry Pi's are sort of pricy right now, so you can look on ebay or elsewhere to see if there are any deals. You will need a SD card. If you do not already have one, this is a good one:
amzn.to/3KcXTn2
I like using a wireless keyboard and mouse to have fewer wires. You can certainly use your USB keyboard and mouse, but if you want a nice wireless one, this one works on the pi. We demonstrate this by using a button switch to control a LED.
amzn.to/36Rv9Sk
You guys can help me out over at Patreon, and that will help me keep my gear updated, and help me keep this quality content coming:
/ paulmcwhorter
[Disclosure of Material Connection: I am a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to amazon.com. ]
#GPIO
#RGB
#RASPBERRYPI

Пікірлер: 102
@cbrombaugh
@cbrombaugh 2 жыл бұрын
I AM LEGEND! To make this program less tedious I just used 10 steps for each color instead of 100, but it still makes a lot of colors. Thanks for all these most-excellent lessons Paul.
@exactlywhatineeded
@exactlywhatineeded 2 жыл бұрын
Very happy to see you still making videos. I’m planning on going back and learning from your beginner tutorials.
@paulmcwhorter
@paulmcwhorter 2 жыл бұрын
Great to hear!
@thealetree
@thealetree Жыл бұрын
Paul, this series is amazing. Not only is the content awesome, but the pace is just right for someone dipping their toes into the hardware side of things for the first time. On top of that, This just feels fun, wholesome, safe, inviting and encouraging. What a great vibe! How lucky are we all to come across a super knowledgable guy sharing some code/hardware/math goodness with everyone out here. Thanks a bunch :)
@paulmcwhorter
@paulmcwhorter Жыл бұрын
Glad you enjoy it!
@danstachelski9185
@danstachelski9185 2 жыл бұрын
I am legend. Got this one working. Based entirely on your most excellent previous lessons, of course. Looking forward to Lesson 13. Keep up the good work, my friend!
@opalprestonshirley1700
@opalprestonshirley1700 2 жыл бұрын
These lessons take me back several years to Arduino, and to my start in electronics and it's still as much fun as ever. I programmed for many years but never had as much fun as when we added hardware into a project we needed to control, to the good times. God Bless you and the family.
@paulmcwhorter
@paulmcwhorter 2 жыл бұрын
I agree. I was never really motivated much by just coding because it was just numbers and words on the screen. But when you have a microcontroller on a board in front of you and it is turning a motor on on conditions you define, and you are sitting right there working with the silicon . . . that is like real magic. Will never forget the first time I programmed a microcontroller in assembly to do a real function . . . ah magic. And may God richly bless you as well.
@opalprestonshirley1700
@opalprestonshirley1700 2 жыл бұрын
@@paulmcwhorter I remember my first Microcontroller it was an Intel 8051 and it only supported Assembly language joy of joys. Oh yeah, those were the days.
@acrowe2512
@acrowe2512 2 жыл бұрын
I'm amazed with the technique you taught with using the LED state as the output to the LED. With my first attempt to do this back in the toggle switch lesson I had the LED state set as 'on' or 'off' as strings which made it difficult to get to work here with 3 LED states. It worked in the toggle switch lesson but when I went to apply that same method here I soon realized it was a complicated mess and I folded up like a cheap Walmart lawn chair, Went back and watched how you did the toggle switch code a bit more closely. It took me a while to wrap my head around your method I think because I kept confusing the LED state with the Button state. Nice project. Made me think. Thank you sir.
@gotomt
@gotomt Жыл бұрын
I am legend!!!! Love the lessons. Catching up to live. Doing 2-3 lessons a week until I make it!!
@keyboardlearning7552
@keyboardlearning7552 2 жыл бұрын
Many thanks for another great lesson. When I started to think about the homework, it took me a moment or two to realise that I could use the expression "...=GPIO.PWM('pin_number', 'frequency') more than once, with a different object Identifier before the "=". When I came to run it, I held my breath really well, because it worked correctly, without any problems. Looking forward to this Thursday's lesson
@paulmcwhorter
@paulmcwhorter 2 жыл бұрын
Excellent!
@jessekloberdanz246
@jessekloberdanz246 2 жыл бұрын
Looking forward to the homework on this one. The buttons will be fun. Back when I did your Arduino lessons with the RGB LED, I took it a step further and added 3 potentiometers to adjust each of the RGB values so I could custom mix colors on the fly. This would be fun to combine the RPi to that project with the buttons. Thank you for another great video.
@paulmcwhorter
@paulmcwhorter 2 жыл бұрын
Excellent!
@robertnowak7784
@robertnowak7784 2 жыл бұрын
I am a legend and love the content of all your videos! It is awesome how you are able to explain things. Wish my teachers in school - back in the days - would have been like this.
@DanielRhoades4122
@DanielRhoades4122 Жыл бұрын
I AM UBER SUPER DUPER LEGEND!!!!! I got this one workin on the first try without makin any mistakes or errors. I did have to reference the toggleLED lesson on 2 occasions. I'm tellin ya, Paul, this one made me feel like a superhero!!! I AM DANIEL . . . CONTROLLER OF LEDS!!! lol. This homework gave me the motivation to keep goin deeper down this rabbit hole. I'm excited to see what's next . . . let us go, once more, through the looking glass!!!
@paulmcwhorter
@paulmcwhorter Жыл бұрын
LEGEND!
@martinlewis645
@martinlewis645 Жыл бұрын
Thanks Paul. Another fantastic lesson. Legend!
@paulmcwhorter
@paulmcwhorter Жыл бұрын
LEGEND!
@pralaymajumdar1206
@pralaymajumdar1206 2 жыл бұрын
Outstanding lesson sir.. U r really a magic man & ur expression of success is just awesome 🙏🙏
@anurasenarathna1703
@anurasenarathna1703 Жыл бұрын
A great tutorial series. Thank you very much.
@patrickfox-roberts7528
@patrickfox-roberts7528 Жыл бұрын
Love watching all the little ants which seem to be interested also :)
@aman-sood
@aman-sood 2 жыл бұрын
Upgraded to Raspberry Pi OS 64 bit today to better use those 8 gigs worth of RAM!
@stevephillips5392
@stevephillips5392 2 жыл бұрын
Hi Paul. I got the homework done eventually. I only had a common anode RGB LED handy, so I made the logic adjustments I felt were needed for that. I decided to leave the switches connected to ground and used the same logic for the switches that you were using in the toggle lesson. However I did note an unusual behavior - in this configuration, it takes two presses of any channel switch to get the light to turn on initially. After that it only needs one press to toggle back and forth. Maybe, in order to switch state on the first press, the switches for common anode LED's MUST be connected to 3.3v instead of ground. I'll look at it some more... Anyway thanks for the great lessons, Steve
@mustafaalwash6952
@mustafaalwash6952 2 жыл бұрын
mr Pual i have seen every single video in the series and every single one of them was wonderfully presented and explained thank you so much....but could you do a video about when to use a resister ? I know what they do but I dont know when and where do we put them.......Now from watching your videos I noticed that we almost always link them with a wire and a LED but can you do a video explaining why is that ?
@HelloWorld-lt5oc
@HelloWorld-lt5oc 3 ай бұрын
Hello, I know this is an older video but can you explain the wiring on the inputs having no external voltage? It seems like when you set the pull in the program it tells the Pi to “internally” set the supply voltage to the input pin
@eugeneamoakwah278
@eugeneamoakwah278 2 жыл бұрын
very powerful lessons, thanks very much,
@paulmcwhorter
@paulmcwhorter 2 жыл бұрын
Glad you enjoyed it
@fuwingpang5445
@fuwingpang5445 2 жыл бұрын
Dude, love the vid. Just wanted to say you sound like Owen Wilson 👍
@pierrelalanne5607
@pierrelalanne5607 2 жыл бұрын
Very nice lesson ... but I use Thonny to program your lesson and find it very user friendly and also you can copy and paste easely... Pierre from Montreal, QC. Canada
@badger5821
@badger5821 2 жыл бұрын
your lessons are very helpful i have learnt arduino
@paulmcwhorter
@paulmcwhorter 2 жыл бұрын
Excellent
@badger5821
@badger5821 2 жыл бұрын
@@paulmcwhorter thank you
@danielwinegardner6909
@danielwinegardner6909 Жыл бұрын
I AM LEGEND!! I just add to the toggle switch code for color
@paulmcwhorter
@paulmcwhorter Жыл бұрын
LEGEND!
@ntandodube4350
@ntandodube4350 2 жыл бұрын
Hello Sir. Will the Raspberry Pi 3 Model A+, RPI3-MODAP - Single Board Computer be sufficient for these lessons?
@PlausibleIdea
@PlausibleIdea 2 жыл бұрын
Paul - wonderful tutorials thank you. I tried using 2 if statements instead of the not statement to toggle the led. The first if statement executed and turned the led on but the second if statement would not execute. I verified the spacing is correct - thoughts?
@PlausibleIdea
@PlausibleIdea 2 жыл бұрын
if I use an if - else statement it works the code im using is if rled == 1: rled = 0 if rled == 0: rled = 1 fairly straightforward
@JoRogan-l1v
@JoRogan-l1v Жыл бұрын
Great video
@endrefidje5698
@endrefidje5698 2 жыл бұрын
Nice tutorial ! Keep them coming ... ;-)
@jimbarrett2152
@jimbarrett2152 2 жыл бұрын
Hi Paul , Respectfully, Would you discuss how to shift out 1’s or 0’s through a shift register to have a particular LED receive a 1 and the rest 0’s / how is this done
@keithlohmeyer
@keithlohmeyer 2 жыл бұрын
I am sure Paul will be using the shift register in the Raphael kit at some point. If you are in a hurry there are several example projects on the Raphael tutorial website listed on the top of the kit box. Shift registers work by filling an input register on the chip one bit at a time by toggling the shift clock pin while setting the data pin as each bit is shifted into the register. When the register has all 8 bits loaded the register latch pin is toggled to send the byte all at once to the output register. So by using just 3 pins you get 8 outputs or more if you daisy chain the shift registers.
@mmulisha1022
@mmulisha1022 Жыл бұрын
I folded up... :( Small error i couldn't figure out without jumping to the next video. I didnt create separate variables for each pwm change. Couldn't figure out why i was getting only one color on. But made it 90% of the way...
@carol-lo
@carol-lo Жыл бұрын
Beautiful !
@paulmcwhorter
@paulmcwhorter Жыл бұрын
Thank you!
@ScottSummerill
@ScottSummerill 2 жыл бұрын
How is this new kit any different from the Elegoo Starter Kit used in other tutorials?
@paulmcwhorter
@paulmcwhorter 2 жыл бұрын
Yes, this has parts tailored to the pi. Many parts that are not in the elegoo kit.
@bamshaknaphtali5963
@bamshaknaphtali5963 2 жыл бұрын
Thank you for your video tutorials, sir. I've really leaned a lot from you. My question is this, sir, how can I write a python code that uses button to call a terminal window and run a code (for example, sudo python helloworld.py)? What I want to achieve is that I want to easily control the pi (through the terminal) without needing a monitor or keyboard. Thank you sir, as I look forward to your response
@badger5821
@badger5821 2 жыл бұрын
5 lessons a day
@jameslewellen150
@jameslewellen150 2 жыл бұрын
I noticed the GPIO series only uses the nano editor. I tried the visual studio code editor, it does not recognize the RPi.GPIO module. Why??
@keithlohmeyer
@keithlohmeyer 2 жыл бұрын
I have been using VSC on the RPi for these lessons and have had no problem using RPi.GPIO. I am using the Raspberry Pi OS 32 bit and the library comes with it.
@jameslewellen150
@jameslewellen150 2 жыл бұрын
@@keithlohmeyer I tried using the Pi 3B+ with VSC, but its a little under powered for VSC, all though it does work, I guess is a problem with windows 10.
@floridian080
@floridian080 2 жыл бұрын
I've been using VS Code on Pi400 for the Paul's Pi lessons w/o difficulty. I don't recall if I had to import any libraries.
@Wythaneye
@Wythaneye 2 жыл бұрын
A couple things I had to do. First, I'm using a python venv with VS Code, so I had to make sure that Rpi.GPIO was installed in that venv. Then as a non-root user, I had to make sure that my user was a member of the gpio group in /etc/group. This caught me of guard when I created a dedicated 'dev' user. Once I had both of those resolved, I am able to use Rpi.GPIO in VS Code.
@Wythaneye
@Wythaneye 2 жыл бұрын
Here's my video on setting up my Pi for Paul's classes, using VS Code. 18 minutes long and probably not a lot of new content for you, but maybe it'll jog your mind a bit and you'll find an answer. kzbin.info/www/bejne/fKGqanyigLuip9E
@badger5821
@badger5821 2 жыл бұрын
also jetson nano
@versehitz
@versehitz 2 жыл бұрын
Paul plz make a montage of you mention Ice cold coffee
@lorisrobots
@lorisrobots 2 жыл бұрын
I enjoyed this project and spent way too much time improving my code and videos. I added in the nonlinear change in duty cycle to allow for consistent perceived brightness changes. Here is my solution with three push-buttons: kzbin.info/www/bejne/rpPWiqGkgtZ5fLs. I had three more buttons from another kit so I also did the project using six pushbuttons. Two buttons per color: one for decreasing brightness, one for increasing: kzbin.info/www/bejne/eJjCq2BjeaqonJI Thanks for the great project Paul!
@WilliamBurlingame
@WilliamBurlingame 2 жыл бұрын
My lesson 12 homework is now working.
@suelingsusu1339
@suelingsusu1339 2 жыл бұрын
Nice!!!🖖🖖🖖🖖🖖🖖
@michaelschweizer2115
@michaelschweizer2115 2 жыл бұрын
Hello Paul. I found my Raspi Gen 1b and decided to do the homework on this legendary piece of electronics. The pinout is slightly different. See the result here: kzbin.info/www/bejne/paScfpSvYtNla9U P.S. I was a bit distracted by my favorite youtube videos.
@paulmcwhorter
@paulmcwhorter 2 жыл бұрын
Nice work.
@brucemilyko8549
@brucemilyko8549 Жыл бұрын
I am Legend!
@liamoliverdarroch6482
@liamoliverdarroch6482 11 ай бұрын
I am legend!
@paulmcwhorter
@paulmcwhorter 11 ай бұрын
LEGEND!
@badger5821
@badger5821 2 жыл бұрын
i will make the most powerful robot the world will ever see "evil laughter"
@badger5821
@badger5821 2 жыл бұрын
i want to finish arduino by june
@trevorblanchard923
@trevorblanchard923 4 ай бұрын
I am a Legend
@paulmcwhorter
@paulmcwhorter 4 ай бұрын
LEGEND!
@davidschnider1297
@davidschnider1297 Жыл бұрын
I am Legend... thanks, Paul... another great and FUN class.. having a BLAST .. so, so enjoying combining coding and HARDWARE .... I love HARDWARE... excited to learn what you have next for us.. God bless you, Paul... oh... here is a link to my homework assignment: kzbin.info/www/bejne/r6faeqOijdGXjtE
@paulmcwhorter
@paulmcwhorter Жыл бұрын
Have fun!
@syohomuga
@syohomuga 3 ай бұрын
from time import sleep import RPi.GPIO as GPIO delay =.1 inR = 36 inG = 38 inB = 40 outR = 37 outG = 35 outB = 33 GPIO.setmode(GPIO.BOARD) GPIO.setup(inR, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(inG, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(inB, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(outR, GPIO.OUT) GPIO.setup(outG, GPIO.OUT) GPIO.setup(outB, GPIO.OUT) """ 0 = off 1 = R 2 = G 3 = B """ try: status = 0 readR_old = 1 readG_old = 1 readB_old = 1 while True: readR = GPIO.input(inR) readG = GPIO.input(inG) readB = GPIO.input(inB) if readR - readR_old == 1: if status == 1: GPIO.output(outR, 0) status = 0 else : GPIO.output(outR, 1) GPIO.output(outG, 0) GPIO.output(outB, 0) status = 1 if readG - readG_old == 1: if status == 2: GPIO.output(outG, 0) status = 0 else : GPIO.output(outG, 1) GPIO.output(outR, 0) GPIO.output(outB, 0) status = 2 if readB - readB_old == 1: if status == 3: GPIO.output(outB, 0) status = 0 else : GPIO.output(outB, 1) GPIO.output(outR, 0) GPIO.output(outG, 0) status = 3 readR_old = readR readG_old = readG readB_old = readB sleep(delay) except KeyboardInterrupt: GPIO.output(outR, 0) GPIO.output(outR, 0) GPIO.output(outR, 0) GPIO.cleanup() print(" cleanup has been done.")
@freddyveza
@freddyveza Жыл бұрын
I am legend
@paulmcwhorter
@paulmcwhorter Жыл бұрын
LEGEND!
@shreyasrawat2930
@shreyasrawat2930 Жыл бұрын
I am Legend
@paulmcwhorter
@paulmcwhorter Жыл бұрын
LEGEND!
@keithlohmeyer
@keithlohmeyer 2 жыл бұрын
Homework posted...sort of. kzbin.info/www/bejne/lYuolIR8Zr6NeJI Paul may say I folded up like a lawn chair this week because I did the HW a different way. Still learning! Thanks Paul for all you do.
@paulmcwhorter
@paulmcwhorter 2 жыл бұрын
Love how well the colors show with the ornament . . . wish I had one.
@hammadahmed3409
@hammadahmed3409 Жыл бұрын
Homework kzbin.info/www/bejne/nqXYq32Ba6drqKM I am curious to know why we use logarithm to calculate button press, we can also divide 100 by button press and then multiply constant with button press to get the brightness
@paulmcwhorter
@paulmcwhorter Жыл бұрын
Which is really a way of doing logarithms
@peterbush3972
@peterbush3972 Жыл бұрын
I am legend
@paulmcwhorter
@paulmcwhorter Жыл бұрын
LEGEND!
Raspberry Pi LESSON 13: Set Color of RGB LED with Push Buttons
46:40
Как Ходили родители в ШКОЛУ!
0:49
Family Box
Рет қаралды 2,3 МЛН
Ozoda - Alamlar (Official Video 2023)
6:22
Ozoda Official
Рет қаралды 10 МЛН
Жездуха 42-серия
29:26
Million Show
Рет қаралды 2,6 МЛН
WAY faster than a Raspberry Pi-but is it enough?
17:26
Jeff Geerling
Рет қаралды 679 М.
Raspberry Pi LESSON 19: Simple Control of Servo From Raspberry Pi
27:14
This is how you destroy Raspberry Pi
9:10
Jeff Geerling
Рет қаралды 473 М.
I Made The Ultimate Cheating Device
9:39
ChromaLock
Рет қаралды 1,2 МЛН
The Petabyte Pi Project
22:27
Jeff Geerling
Рет қаралды 2,2 МЛН
3 engineers race to design a PCB in 2 hours | Design Battle
11:50
Predictable Designs
Рет қаралды 316 М.
Control you Raspberry Pi with a BUTTON
12:03
Sam Westby Tech
Рет қаралды 21 М.
Как Ходили родители в ШКОЛУ!
0:49
Family Box
Рет қаралды 2,3 МЛН