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...
For this recipe, configure the circuit as follows:
Next, create the
toggle.py
file, and put in the following code to test it out:    #!/usr/bin/env python     # Raspberry Pi Zero Cookbook     # Chapter 8     # Toggle Switch and Debouncing     import time     import RPi.GPIO as GPIO     GPIO.setmode(GPIO.BCM)     GPIO.setwarnings(False...