update the macro definition ' #define num_switches ' to be the number of button switches you are connecting.wire up the switches according to the above choices and connect to the microcontroller.for each button switch decide how it should be wired - either as ' circuit_C1 ' or ' circuit_C2 '.decide how many button switches you wish to configure.However, the steps to be followed will be: Implementation of the sketch is reasonably straight forward and can be directly worked out by reference to the OOTB sketch. That's it, all very clear, but let's see how we can vary things. If a switch press is detected, allowing for debounce, the read function returns a 'switched' status result which is then actioned by a corresponding main loop switch-case statement. Once configured, the sketch will poll each declared button switch in turn in accordance with its definition/specification. But through the configuration of switch data held in a switch control structure, multiple button switches may be efficiently supported, configured in either or a mix of both circuit styles (circuit_C1 and/or circuit_C2). The OOTB sketch has been preconfigured for six button switches, each wired for circuit_C2 - the simplest wiring scheme. For instance, the Arduino Mega 2560 will support literally dozens of digital switch connections - enough for a mock up of the Star Ship Enterprise bridge! However, 'out-of-the-box' (OOTB), the sketch is configured for just six button switches so my UNO is a good choice. The number of button switches that can be connected in this way is therefore determined by the architecture of the microcontroller used. The sketch is able to support many button switches each connected to a digital pin. If you are unsure then have a look at the tutorial mentioned above, that is Understanding & Using Button Switches. When implementing the sketch it essential to decide which switch wiring scheme is used for each button switch you wish to connect as this has a fundamental bearing and affect on how the inputs are interpreted for switch ON and OFF. In summary, the two commonly seen button switch wiring schemes are: The design of the sketch is such that button switches may be wired in either way or a mixture of both - the sketch may be easily configured to work with either or a mix of both wiring styles. The example sketch at the centre of this article is capable of working with multiple button switches wired in either commonly seen designs - circuits incorporating pull down 10k ohm resistors (see figure 1) or without (see figure 2). If it is that you wish for a deeper understanding in the theory and implementation of simple button switches, then please do refer to this tutorial. The background and basis to the methods offered here are largely those put forward in that tutorial. The article builds on the approach and techniques laid out in a previous publication (a tutorial), namely Understanding & Using Button Switches. This article offers a highly configurable approach to implementing multiple button switches in a simple, direct but reliable way and using a technique of switch 'polling'.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |