mirror of
https://github.com/taigrr/arduinolibs
synced 2025-01-18 04:33:12 -08:00
78 lines
3.1 KiB
Plaintext
78 lines
3.1 KiB
Plaintext
/*
|
|
* Copyright (C) 2012 Southern Storm Software, Pty Ltd.
|
|
*
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
* to deal in the Software without restriction, including without limitation
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
*
|
|
* The above copyright notice and this permission notice shall be included
|
|
* in all copies or substantial portions of the Software.
|
|
*
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
* DEALINGS IN THE SOFTWARE.
|
|
*/
|
|
|
|
/**
|
|
\file blink-charlieplex.dox
|
|
\page blink_charlieplex Charlieplexing Example
|
|
|
|
<a href="http://en.wikipedia.org/wiki/Charlieplexing">Charlieplexing</a>
|
|
is a technique for multiplexing large numbers of LED's on a small
|
|
number of microcontroller output pins. LED's are arranged in
|
|
complementary pairs and managed by the Charlieplex class. For this
|
|
example we are going to use 3 output pins to drive 6 LED's:
|
|
|
|
\image html charlieplexeg.png
|
|
|
|
The technique can be expanded to even larger numbers of LED's.
|
|
See the documentation for the Charlieplex class for a description of
|
|
how to connect up larger numbers of pins in a Charlieplexed arrangement.
|
|
|
|
The first step is to initialize a Charlieplex object with the output
|
|
pins it needs to drive:
|
|
|
|
\dontinclude BlinkLED/examples/Charlieplex/Charlieplex.ino
|
|
\skip #include
|
|
\until charlie
|
|
|
|
Then in <tt>setup()</tt> we use Charlieplex::setLed() and
|
|
Charlieplex::setPwmLed() to set three of the six LED's to
|
|
the desired output values:
|
|
|
|
\dontinclude BlinkLED/examples/Charlieplex/Charlieplex.ino
|
|
\skip setup
|
|
\until }
|
|
|
|
Charlieplexing can only light a single LED at a time. It is therefore
|
|
necessary to constantly scan the entire LED array, alternatively turning
|
|
LED's on and off. The user's peristence of vision fills in the gaps.
|
|
To do this, we call Charlieplex::loop():
|
|
|
|
\dontinclude BlinkLED/examples/Charlieplex/Charlieplex.ino
|
|
\skip loop
|
|
\until }
|
|
|
|
The downside of Charlieplexing is that when multiple LED's are lit, each LED
|
|
will appear to be dimmer than if only a single LED was lit. This can be
|
|
counteracted by using brighter LED's or smaller resistors. The danger with
|
|
smaller resistors is that if the program crashes or locks up for some reason,
|
|
a large amount of continuous current could be fed through a single LED and
|
|
cause it to exceed its maximum rating and burn out.
|
|
|
|
The full source code for the example follows:
|
|
|
|
\include BlinkLED/examples/Charlieplex/Charlieplex.ino
|
|
|
|
A more complex example that performs a LED chase over the 6 LED's follows:
|
|
|
|
\include BlinkLED/examples/CharlieplexChase/CharlieplexChase.ino
|
|
*/
|