Interfacing toggle switches and setting debouncing

If you tried the previous recipe, you probably noticed that the color cycling switched quickly while the button was pressed. This was because the input behavior would loop as fast as the Raspberry Pi Zero could process the input, which is pretty fast! A simple software method to allow for a more human-speed signal recognition is called debouncing.

Getting ready

You'll want the following equipment in addition to your Raspberry Pi Zero, a breadboard, and jumper wires:

  • Two 330-Ohm resistors
  • Two LEDs, any color
  • Three-way toggle switch (A\off\B)
  • Tactile pushbutton

How to do it...

  1. For this recipe, configure the circuit as follows:

  2. Next, create the toggle.py file, and put in the following code to test it out: ...

Get Raspberry Pi Zero Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.