Raspberry Pi LESSON 10: Making a Dimmable LED with Two Push Buttons
HTML-код
- Опубликовано: 11 сен 2024
- Guys the pinout I show in this video has an error on Tx/Rx. You can download your own correct Pinout from my WEB site HERE:
toptechboy.com...
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 create a dimmable LED using two button switches. One is for brightening, and the other for dimming. We will use internal pullup resistors, and we will use PWM on the GPIO pin for the LED.
If you guys are interested in the oscilloscope I am using, you can pick one up here (affiliate link):
amzn.to/3v13Mhl
Also, you should pick up a pack of the neat little straight jumper wires to make your breadboard builds neater and more organized.:
amzn.to/3DtWpm9
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
#PWM
#RASPBERRYPI
I am legend, I like how your solutions are elegant and address the minutest problems! Also like how you implement math into all of this. Thanks for everything you do.
Paul,
I hit a rough patch a couple of weeks back and chuffed like three assignments in a row. So, I went all the way back lesson six when we started on internal resistors and went through all the work again. I'm really proud to say that I was able to do them the second time through. Yes, I may have remembered some amount of what you covered the first time but believe me when I say that there was plenty that I didn't!
I did this whole dimmer switch problem on Notepad before I committed a single line of code to the terminal and still had another couple of hours worth of head scratching and debugging. I felt like I had really accomplished something when I finally worked out all the bugs.
I AM LEGEND! BUT--- I did the original homework on my own and it worked as required. I then entered Paul's modified version with the 10 button press modification and found an error. It technically worked as described , but extra up button presses make BP continue to increase and require extra down button presses until the brightness starts to decrease. Of course, this is easily fixed. I just wanted Paul to see that someone is actually following his lessons in detail. 🙂 Thanks for all the time and effort you devote to these courses, Paul.
😍😍 What an amazing content. I really admire you for you huge knowledge Mr Paul. Plus don't ever stop sharing it with us!
Great work you do Mr. Paul. we need more people like you willing to share the knowledge God Bless you and you family....
I didn't use logs in my programs. I just took the nth root of 100 to get the increments in brightness.
Pi 4 version (code in description) - ruclips.net/video/EwQUzXukUAo/видео.html
Pico version (code in description) - ruclips.net/video/edWcbNIrXn4/видео.html
Loved this lesson!!
But instead of introducing a new variable BP we can just divide DC by 1.589 or multiply it with 1.589
Same as we did with 2 and we got 7 button pushes
I’m working through these lessons with my 10 year old son. He had just just crashed the program when you called out the guy who will “sit there and push the button until you crash the program, and you know who you are.” He looked at me and said, “I’m the guy!” and then almost fell out his chair laughing. Very funny moment
funny!
Fantastic lesson and the math is so awesome !!!!! A lesson on logarithms would be great and very helpfull for future lessons.
Cool! I enjoyed the refresher on logarithms.
Thanks for adding in the log lesson and how to deal with the nonlinearity of brightness. I noticed that it was not linear as I was coding but I left my solution with linear change. I think I was distracted by cute cat videos 🙂!
Thanks for showing us the Log function. I would like to see you do a lesson on logs.
I am legend! Thanks for these tutorials Paul, it’s massively helping for my dissertation. I used an array to select the duty cycle which was no way near as tidy as DC*2, but I felt pretty smug when I realised my way bypassed doing logs!
Cheers from the UK
LEGEND!
Anything that speeds the accuracy and ease of design for our work is great. Love the math. God Bless.
Thank you!
@@paulmcwhorter You are welcome.
Thanks for the refresher on logarithms.
I am Legend. Mine worked at the second attempt! This is a great explanation of logs. Well done, and many thanks for this series.
This is another Great Lesson! Hope you have a safe time in the bush!
very nice explanation sir
This is so much fun!
GREAT, fun lesson, Paul... yes.. one of the 1st times using logarithms OUTSIDE of an academic environment... POWERFUL tool, indeed... these HAVE been exciting lessons ... and I am ready and eager to move on to the next lesson.. Blessings...
Glad it was helpful!
Great Lessons!!! Just wondering why you are not using Thonny since it is included in the Raspberry Pi OS?
Sadly my Raspberry Pi is still the boss. As an old guy (65) I have learnt over the years that maths is the language of engineering, so keep serving it up.
Fantastic lesson. I'm going to redo my homework using the python math module (if I can!) and then measure the DCs with my newly acquired cheap USB oscilloscope. But don't hold your breath!
How did I miss this??? Paul did you change the schedule? This premiered at 3 AM where I live
You are really a magic man.. 🙏🙏🙏
Hi Paul. I found that I need to restrict the range of BP [ if BP>10: BP=10 and if BP
Well, This is the third time my comment is deleted... This time just say I'm legend, thanks Paul for making this lessons
really sir, your are great JAADUGAR😊😊😇💕
Thanks for the math @Paul McWhorter! Feel free to do a log lesson or even a full ‘Math for Engineering’ tutorial series!
I am legend!
Will be watching for an opportunity to use exponents for steps.
LEGEND!
I would like to see livestreams where the audience can ask questions about math.
Hey, just wanted to mention why you can use 0 for the duty cycle, while not being able to use 99. This is because 0 is inclusive, and 100 would be exclusive. Because if you think about it, since 0 is allowed, and up to 99 (including 99), that is actually 100 values for you to choose from (0-99). If it did allow 100, it would be 101 values you can choose from (0-100) which makes no sense.
I understand what you are saying, but from a practical point, I would like the option of turning the signal completely off by having a duty cycle of 0 and have it on all the time with a duty cycle of 100. Now, with PWM, I can only have 99% of full signal. Practically, it is OK if that took 101 steps.
I am legend. Thanks for the lesson on using log maths.
LEGEND!
Bravo!!!
Awesome !
Young me: I’ll never use this math stuff…
Mr. McWhorter: Oh my sweet summer child (takes a sip of his coffe)
Hi Magicman Paul, could I use my components from arduino kits in Raspberry Pi project? Many thanks!!! Looking forwards to your reply😊
cool it worked here
I was legend! I say WAS, because though my code works I see some improvements it needs. I'll get my original solution and then my revised solution posted.
I'm confused about the hour of this lesson. Normally it's at 17.00 hours my time, this time it was 17 hours before this, so at midnight for me. Did you change the hour Sir and what about the future lessons?
It was a mistake Wendy. A simple mistake! I probably confused AM and PM when I posted it. I actually slept through the premier so it got me off guard as well. My apologize
I am legend! finally lol
I AM LEGEND!!!!!!!
LEGEND!
Please try ‚,except InvisibleKeyInterrupt:‘‘ :). Thanks a lot for the tutorials!!
I am legend!
LEGEND!
why did we need to do the whole thing with the logs? If using a calculator is ok why not just do
100 = A^10
root10 of 100 = A or 100^(1/10) = A
1.5849 = A
Exponentials and logs are two sides of the same coin. It is fine to use exponentials, but there is no reason to try to avoid understanding and using logs. Most real world engineering problems require understanding of logs, so we should become comfortable with them
sir what is AI , ML,DL, DATA SCIENCE ,NLP
I folded up like a cheap walmart lawn chair BROTHER
Yet you will get up, dust yourself off, and try again. Next time, LEGEND!
@@paulmcwhorter Thanks man!
I say that because I didn't do the homework, but I have been using your lessons to try to control a synthesizer circuit i've been playing with.
Your videos have been very helpful in my quests to experiment!
I am legend
🙏🙏👍
Coffee without sugar will be very bitter.
Not at all!
Like the use of logarithms for determining steps. Thanks. Why not put the math in the program after you explained it, instead of the calculated value? Let the program do the work.
Yes, you could have an input for the number of pushes you want (n) and then take the nth root of 100. :)
Iam legend (LOL)
Life is busy, what can I say. I finally got my video posted for lesson #10. Similar to #9 but with an exponential scale instead of linear. ruclips.net/video/Bfvy2q8cRhc/видео.html
Excellent
I found out that it could also be done this way: Taking the 10th root is by far the easiest, But if you insist on involving logarithms, you can utilize the rule log(𝑎𝑏)=𝑏∗log(𝑎), but all that really gives is a complicated expression for 10th root of 100 (stackexchange)
ln(𝑎)=[ln(100)]÷10≈0.4605. Therefore, 𝑎≈𝑒 power 0.4605≈1.585
The math is really the same. What you are doing is correct, and works the same, and in fact the rules you are using are part of the rules of logarithms. Just in this case, you can write the problem such the logs cancel themselves out. Taking roots is a very fine way of doing it. I do really love tis type of math
from time import sleep
import RPi.GPIO as GPIO
delay =.1
inPin_1 = 29
inPin_2 = 33
outPin = 37
GPIO.setmode(GPIO.BOARD)
GPIO.setup(outPin, GPIO.OUT)
GPIO.setup(inPin_1, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(inPin_2, GPIO.IN, pull_up_down=GPIO.PUD_UP)
myPWM = GPIO.PWM(outPin, 100)
try:
brightness = 50
readVal_1_before = 1
readVal_2_before = 1
myPWM.start(brightness)
while True:
readVal_1_now = GPIO.input(inPin_1)
readVal_2_now = GPIO.input(inPin_2)
print(readVal_1_now, readVal_2_now)
if readVal_1_now - readVal_1_before == 1:
brightness = max(0,brightness-10)
myPWM.ChangeDutyCycle(brightness)
print(str(brightness) + "%")
elif readVal_2_now - readVal_2_before == 1:
brightness = min(100,brightness+10)
myPWM.ChangeDutyCycle(brightness)
print(str(brightness) + "%")
readVal_1_before = readVal_1_now
readVal_2_before = readVal_2_now
sleep(delay)
except KeyboardInterrupt:
myPWM.stop()
GPIO.cleanup()
print(" cleanup has been done.")
I am legend
LEGEND!