Go Down

Topic: New Library for BiColor LEDs (Read 5 times) previous topic - next topic

wolfgang42

Version 1.2 released with Arduino 1.0 support. Thanks PaulDriver for the patch!

PaulDriver

No problem, it was a minor thing.

Thank you for sharing your library.

teckel


Version 1.2 released with Arduino 1.0 support. Thanks PaulDriver for the patch!


I also have a library (toneAC) that does "AC" to drive a speaker at almost twice the volume as the standard tone library.  This is possible because I alternate the 5 volts between two pins.  In my case, it's designed to be extremely fast, so I use the Arduino's PWM pins and timer 1.  This also allows for perfect switching between the two pins without any programming slowing things down.

As a bonus, my library can also drive a bicolor two pin LED as yours does (one of my example sketches included with the library controls a bicolor LED with a pot to adjust the cycle speed).  You may want to check out my source.  As toneAC is designed for ultra speed and accuracy, you must use the timer 1 controlled PWM pins.  It also is totally driven totally by port registers for the fastest and smallest code.  Looking at my library may assist you.  I also have a NewTone library thats a modified version of toneAC but allows you to specify what pin you want to drive a speaker with.  This also may assist you with your library.

While writing library using port registers and timers may be a little more challenging at first, it's really not that hard once you do it a few times.  And, the benefits are many.  Very small code size, very fast, color switching and duty cycle can all be done in the background, no reason for delay statements which can kill a project, etc.

Best of luck with your project!

Tim
Arduino - Teensy - Raspberry Pi
My libraries: NewPing - LCDBitmap - toneAC - NewTone - TimerFreeTone

wolfgang42

I've just released version 1.3 of the BiColorLED library, which fixes the Blink example (I left debugging code in--oops). I've also put the code on GitHub.


I also have a library (toneAC) that does "AC" to drive a speaker at almost twice the volume as the standard tone library.  This is possible because I alternate the 5 volts between two pins.  In my case, it's designed to be extremely fast, so I use the Arduino's PWM pins and timer 1.  This also allows for perfect switching between the two pins without any programming slowing things down.

As a bonus, my library can also drive a bicolor two pin LED as yours does (one of my example sketches included with the library controls a bicolor LED with a pot to adjust the cycle speed).  You may want to check out my source.  As toneAC is designed for ultra speed and accuracy, you must use the timer 1 controlled PWM pins.  It also is totally driven totally by port registers for the fastest and smallest code.  Looking at my library may assist you.  I also have a NewTone library thats a modified version of toneAC but allows you to specify what pin you want to drive a speaker with.  This also may assist you with your library.

While writing library using port registers and timers may be a little more challenging at first, it's really not that hard once you do it a few times.  And, the benefits are many.  Very small code size, very fast, color switching and duty cycle can all be done in the background, no reason for delay statements which can kill a project, etc.

Best of luck with your project!

Tim

I'm not sure how I missed this post before; I probably overlooked the email.

The BiColorLED library is intentionally simplistic: it does something very simple, and does it well. It started out as part of one project, and then I decided to turn it into a library rather than doing a copy-paste. The original project was avoiding delay statements for other reasons, and the timer was being used for something else in the new one. I If anybody needs the features that your library provides (background operation, ultra-fast switching, color ranges) I would suggest that they use that one instead. Not that I don't like the idea of doing those things, but there's no point in reinventing the wheel, and the BiColorLED library tries to stay as simple as possible.

wolfgang42

And another update, version 1.4. This one adds an overloaded setColor(color1, color2) method, and support for different delays on the two blink colors (to allow flashing/winking). As usual, see the Arduino wiki or GitHub to download.

Go Up