Book Image

Raspberry Pi Essentials

By : Jack Creasey
Book Image

Raspberry Pi Essentials

By: Jack Creasey

Overview of this book

Table of Contents (15 chapters)
Raspberry Pi Essentials
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Adding a physical switch interface to the Internet radio


Now that you have had the opportunity to experiment with sensing switches, we need to develop the code to add the external buttons to the Internet radio.

We will use four buttons, which are as follows:

  • Two buttons for scrolling forward and backwards through the playlist using the Spinbox actions

  • A button to select or start the playlist entry

  • A button to stop the radio

  • An LED to indicate each switch entry

  • The mouse interface will still work

The code for adding a switch interface is encapsulated enough to provide a small demo of the buttons in action using IDLE3 before we combine the code.

The complete demo code is shown after the following paragraph. You have the option to type it in and then save it in a file you created, called /home/pi/gpio/tkswitches.py. Or you can download the tkswitches.py code from http://1drv.ms/1ysAxkl.

The code opens an empty TKinter window when started and allows you to test all four buttons and the LED. The only...