This article features a Quick Start Guide for implementing projects that use switches, either single or multiple switches, and offers insights into more complex uses of switches. The approach is principally software driven, requiring few electronic components other than, of course, switches and a resistor or two.
The centre-piece of the Guide is the <ez_switch_lib> library, which is already featured as an article here on the Project Hub (see <ez_switch_lib>).
The Quick Start Guide provides four sketch examples, two for Arduino and two for ESP 32 microcontrollers. However, all examples are suitable for both microcontrollers, just change the pin outs for the board to be used.
In summary, the examples provide basic working sketches (coded only to demonstrate the purpose of the examples) that configure:
1. Single switches - 1 x button switch, on Arduino.
2. Multiple switches - 4 x switches (2 x button and 2 x toggle) wired in different wiring schemes, on Arduino.
3. Multiple switches with links to different digital outputs - as 2 above, but three of the switches are linked to digital output pins that are automatically status switched/flipped on switch actuation (i.e. LOW to HIGH or HIGH to LOW). The example is configured for ESP 32 boards.
4. Multiple switches linked to a common digital output, driving an external interrupt routine (ISR) - as 3 above, with three switches linked to the common digital output pin which triggers an associated ISR whenever one of the associated switches is actuated. The example is also configured for ESP 32 boards.
The level of experience required to follow the Guide's examples ranges from easy to intermediate, but this is something for the reader to judge for themselves.
The Guide offers a 'dip in' approach so that you may home in on a particular example that may suit your specific needs for switches, but it also builds incrementally from one example to the next, bringing into play new features of the <ez_switch_lib> library for greater sophistication. Once you have followed all of the Guide's examples you will have a comprehensive set of tools for your tool box.
However, there is still more that you can leverage from the <ez_switch_lib> library. To explore these features see the <ez_switch_lib> article on the Project Hub (see above link).
The <ez_switch_lib> library Quick Start Guide contains all of the circuit diagrams, sketches, comments and guidance for you to fully explore the basics of the ez_switch_lib library. The Guide may be downloaded from github as a pdf here.
To note is that the examples provided are 'lean', insofar as they only include code sufficient for demonstrating their purpose. For example, whilst error testing code is provided, no error code is. If it is that you wish to add error code to deal with error conditions then add this where indicated.
The downloadable sketches for each of the Quick Guide examples are located with this article - see Code section, below.
Other ResourcesFinally, if you are wondering why mechanical switches are so troublesome then have a look at another Project Hub article called Understanding & Using Button Switches which explains some of the issues they, and other switch types, present for the developer which the <ez_switch_lib> removes by providing a software driven solution.
Comments