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

Комментарии • 86

  • @aman-sood
    @aman-sood 2 года назад +3

    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.

  • @RobVollmar
    @RobVollmar Год назад +2

    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.

  • @cbrombaugh
    @cbrombaugh 2 года назад +3

    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.

  • @theotrg2371
    @theotrg2371 2 года назад +3

    😍😍 What an amazing content. I really admire you for you huge knowledge Mr Paul. Plus don't ever stop sharing it with us!

  • @arguedas02
    @arguedas02 2 года назад +1

    Great work you do Mr. Paul. we need more people like you willing to share the knowledge God Bless you and you family....

  • @charlotteswift
    @charlotteswift 2 года назад +2

    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

  • @krishnapranav9123
    @krishnapranav9123 Год назад +1

    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

  • @smitt76
    @smitt76 Год назад +1

    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

  • @rickbonari4493
    @rickbonari4493 2 года назад +1

    Fantastic lesson and the math is so awesome !!!!! A lesson on logarithms would be great and very helpfull for future lessons.

  • @keithlohmeyer
    @keithlohmeyer 2 года назад +1

    Cool! I enjoyed the refresher on logarithms.

  • @lorisrobots
    @lorisrobots 2 года назад

    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 🙂!

  • @TheUnofficialMaker
    @TheUnofficialMaker 2 года назад +1

    Thanks for showing us the Log function. I would like to see you do a lesson on logs.

  • @magwitch
    @magwitch 6 месяцев назад

    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

  • @opalprestonshirley1700
    @opalprestonshirley1700 2 года назад

    Anything that speeds the accuracy and ease of design for our work is great. Love the math. God Bless.

  • @harrison4687
    @harrison4687 Год назад

    Thanks for the refresher on logarithms.

  • @keyboardlearning7552
    @keyboardlearning7552 2 года назад

    I am Legend. Mine worked at the second attempt! This is a great explanation of logs. Well done, and many thanks for this series.

  • @larryplatzek9017
    @larryplatzek9017 2 года назад

    This is another Great Lesson! Hope you have a safe time in the bush!

  • @TheRaviteja6
    @TheRaviteja6 Год назад

    very nice explanation sir

  • @carol-lo
    @carol-lo 10 месяцев назад

    This is so much fun!

  • @davidschnider1297
    @davidschnider1297 Год назад

    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...

  • @jawasparky6347
    @jawasparky6347 4 месяца назад

    Great Lessons!!! Just wondering why you are not using Thonny since it is included in the Raspberry Pi OS?

  • @MrCameronMoore
    @MrCameronMoore 2 года назад

    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.

  • @itsmeintorrespain2714
    @itsmeintorrespain2714 2 года назад

    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!

  • @aman-sood
    @aman-sood 2 года назад

    How did I miss this??? Paul did you change the schedule? This premiered at 3 AM where I live

  • @pralaymajumdar1206
    @pralaymajumdar1206 2 года назад

    You are really a magic man.. 🙏🙏🙏

  • @robinedminson6461
    @robinedminson6461 Год назад

    Hi Paul. I found that I need to restrict the range of BP [ if BP>10: BP=10 and if BP

  • @freddyveza
    @freddyveza Год назад

    Well, This is the third time my comment is deleted... This time just say I'm legend, thanks Paul for making this lessons

  • @mddanishakhtar9025
    @mddanishakhtar9025 Год назад

    really sir, your are great JAADUGAR😊😊😇💕

  • @Lehibob
    @Lehibob 2 года назад +1

    Thanks for the math @Paul McWhorter! Feel free to do a log lesson or even a full ‘Math for Engineering’ tutorial series!

  • @jonathanlanders9406
    @jonathanlanders9406 Год назад

    I am legend!
    Will be watching for an opportunity to use exponents for steps.

  • @whoknows1893
    @whoknows1893 2 года назад +1

    I would like to see livestreams where the audience can ask questions about math.

  • @kylehoell
    @kylehoell Год назад

    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.

    • @paulmcwhorter
      @paulmcwhorter  Год назад +1

      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.

  • @daviddirac5942
    @daviddirac5942 2 года назад

    I am legend. Thanks for the lesson on using log maths.

  • @suelingsusu1339
    @suelingsusu1339 2 года назад

    Bravo!!!

  • @mohammadm.taheri9303
    @mohammadm.taheri9303 2 года назад

    Awesome !

  • @soteros1983
    @soteros1983 2 года назад

    Young me: I’ll never use this math stuff…
    Mr. McWhorter: Oh my sweet summer child (takes a sip of his coffe)

  • @user-wo3qg1et8r
    @user-wo3qg1et8r 2 месяца назад

    Hi Magicman Paul, could I use my components from arduino kits in Raspberry Pi project? Many thanks!!! Looking forwards to your reply😊

  • @ninjinblox1737
    @ninjinblox1737 2 года назад

    cool it worked here

  • @Wythaneye
    @Wythaneye 2 года назад

    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.

  • @wendygrant2735
    @wendygrant2735 2 года назад

    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?

    • @paulmcwhorter
      @paulmcwhorter  2 года назад

      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

  • @wardeneternal1140
    @wardeneternal1140 2 месяца назад

    I am legend! finally lol

  • @arshdeepsingh5950
    @arshdeepsingh5950 Месяц назад

    I AM LEGEND!!!!!!!

  • @marinkokljajic1725
    @marinkokljajic1725 Год назад

    Please try ‚,except InvisibleKeyInterrupt:‘‘ :). Thanks a lot for the tutorials!!

  • @liamoliverdarroch6482
    @liamoliverdarroch6482 10 месяцев назад

    I am legend!

  • @nikitapolyakov2259
    @nikitapolyakov2259 Месяц назад

    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

    • @paulmcwhorter
      @paulmcwhorter  Месяц назад +1

      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

  • @partharora6023
    @partharora6023 2 года назад

    sir what is AI , ML,DL, DATA SCIENCE ,NLP

  • @yeeha8815
    @yeeha8815 2 года назад +1

    I folded up like a cheap walmart lawn chair BROTHER

    • @paulmcwhorter
      @paulmcwhorter  2 года назад

      Yet you will get up, dust yourself off, and try again. Next time, LEGEND!

    • @yeeha8815
      @yeeha8815 2 года назад

      @@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!

  • @MensahJ
    @MensahJ 2 месяца назад

    I am legend

  • @MultiTechEducation4U
    @MultiTechEducation4U 2 года назад

    🙏🙏👍

  • @Declek-Hub
    @Declek-Hub 2 года назад

    Coffee without sugar will be very bitter.

  • @kenstephens221
    @kenstephens221 2 года назад +1

    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.

    • @TheUnofficialMaker
      @TheUnofficialMaker 2 года назад

      Yes, you could have an input for the number of pushes you want (n) and then take the nth root of 100. :)

  • @mohammadm.taheri9303
    @mohammadm.taheri9303 2 года назад

    Iam legend (LOL)

  • @Wythaneye
    @Wythaneye 2 года назад

    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

  • @TheUnofficialMaker
    @TheUnofficialMaker 2 года назад

    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

    • @paulmcwhorter
      @paulmcwhorter  2 года назад +1

      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

  • @syohomuga
    @syohomuga Месяц назад

    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.")

  • @peterkarlsson7801
    @peterkarlsson7801 2 года назад

    I am legend