New Library for BiColor LEDs

PaulS:

To turn the LED red, pin1 is set HIGH and pin2 is set low, so the power goes one way. To turn it green, the polarity of the two pins is swapped, so the power goes the other way. Yellow is produced by rapidly switching between red and green, producing AC

You are not producing AC. AC is alternating current, where the voltage changes from positive to negative 50 or 60 times per second. All you are doing is switching which way the current, at +5V, is flowing.

I refer you to Merriam-Webster's definition of Alternating Current: http://www.merriam-webster.com/dictionary/alternating+current.

an electric current that reverses its direction at regularly recurring intervals

  • An electric current: This is electricity we're working with, even at 5V.
  • that reverses its direction: in other words, which way the current is flowing
  • at regularly recurring intervals: If you call drive() at regularly recurring intervals (which you should, to make the yellow look right), then the current reverses at regularly recurring intervals.

If there's any part of this you don't understand, have a look at my explanation above, or hook the output of my library up to an oscilloscope and see for yourself.