Book Image

Python Programming for Arduino

Book Image

Python Programming for Arduino

Overview of this book

Table of Contents (18 chapters)
Python Programming for Arduino
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

The Scale() widget – adjusting the brightness of an LED


In this section, we will develop some code to change an LED's brightness using the Python GUI. Previously, we learned that you can use a digital pin of Arduino to produce an analog output using PWM. Although you can use the Entry() widget to provide one time value for the PWM signal, it will be useful to have a widget that can dynamically provide this value. As brightness can be fluctuated between 0 and 100 percent, it makes sense to use a slider that varies between 0 and 100. The Tkinter library provides this kind of sliding interface using the Scale() widget.

As we are working to change the brightness of the LED and supply analog input, we will be using a digital pin with the PWM support. In the previous exercise, we used digital pin 11, which already supports PWM. If you are using a custom version of the circuit different to the one provided earlier, we recommend that you change it to a pin that supports PWM. Now it is time to open...