Raspberry Pi LESSON 31: Making a Dimable LED with Python

In this lesson we are ready to bring together a lot of what we learned in earlier lessons. We will create dimable LEDs which will respond to two buttons. If one is pressed the LED will gradually grow dimmer. If the other is pressed, the LED will gradually grow brighter. This will require us to use our skills in using GPIO inputs, pullup resistors, GPIO outputs, and PWM.

For convenience we will use the same circuit we used in LESSON 30, shown below. Also, if you want to follow along with these lessons, you can buy the gear you need HERE.

Raspberry Pi LED Circuit
This Circuit Controls two LED from Push Buttons Using the Raspberry Pi

The objective of this circuit is that we want the LEDs to grow brighter each time the right button is pushed, and we want them to grow dimmer each time to left button is pushed.

The video above steps through and explains this code.


4 thoughts on “Raspberry Pi LESSON 31: Making a Dimable LED with Python”

  1. Paul,
    Your lesson and videos are great. They have allowed me to quickly learn the basics of arduion and the Pi so that I can share them with my students. I recommend your site to everyone interested in adding tech to their classrooms. How can I subscribe?

    1. There is really nothing to do except subscribe to my youtube channel. I should be making more videos shortly.

  2. Great lessons, I added a GPIO.cleanup() at the start before pin assignment as most of the programs do not allow clean exit just breaks. It stops error messages when first running sometimes.
    Also added similar if statement for less than 1 on the brightness so you cannot go infinitely dim or many steps dim. But you know this..it’s just for beginners like me. Many thanks as always.

  3. SICK and tired of the mouse not working in Nano? I couldnt get over it so I did some research.
    sudo apt-get install gpm
    once installed…
    from now on use sudo nano -m thefileyouwant.txt
    FINALLY! Works in puTTY too! Thanks again Paul for all the hard work you do for your students!

Comments are closed.