This is a simple library to drive a two-lead bicolour LED that's been attached to a pair of pins. It lets you drive both solid colors, as well as allowing you to put the two together "simultaneously" by passing AC current through, rapidly turning on one color, then the other.
For the purposes of this page, I'm assuming you have a red/green LED, but they come in a number of other colors as well. Just alter 'red' and 'green' to whatever two colors your LED supports.
To declare an instance, just use
Bi-color LEDs support 4 colors--off, red on, green on, or alternating both on (making yellow). This library represents these colours as 4 numbers:
You can set the LED's colour with:
If you're using yellow (colour 3) or blinking, you'll also need to call
led.drive(); at least every 9 milliseconds so that the library can alternate the colors without the flickering being obvious. This means that if you use
delay();, the LED will freeze in one colour until the delay finishes.
You can make the library alternate between two colours with
If you want it to alternate with a colour other than black, you can set the second colour with:
To set separate delays for each color, call
Also remember to use
led.drive(); for the reasons stated above.
BiColorLED_H contains the version number of the library, in case you need to check the library version. Note that this number is only incremented when the library itself changes (for example, 1.3 still reports itself as 1.1).
Eventually, I might also add support for varying the ratio of red to green, as well as the duty cycle for blinking.
No known bugs.
Add any bug reports or feature requests here, post them to this forum thread, or email them to the address listed in BiColorLED.cpp and BiColorLED.h