Hello everyone, have a noob question and would like some pointers on how to get started on a project.
I recently got a christmas tree that has the 2 pin bicolor LED's, but its got a piss poor controller which can only blink the 2 colors back and forth.
I'm trying to setup a controller which can:
drive 2 pin bi-color LED's running on 29v, powered by a 29v 0.6A adapter
fade between one color to another using PWM
Have control over the time it takes to fade from one polarity to another
I'll probably need a DC step down buck converter to drive the arduino, and I've found a very good example for driving the color fading through (GitHub - wolfgang42/bicolorled: Library for driving a bicolor LED with Arduino). The tricky part is figuring out how to make use of the PWM voltage to drive LED's from its own power supply.
I'm a programmer used to OOP and I'd love to spend the time and learn how to get started, and would like to ask for some pointers on where to look for projects that have similar properties, whether on the PWM aspect or on driving LED's with it's own power supply. Also any suggestions on hardware would be appreciated.
Thank you in advance for any suggestions and pointers!
I have no idea what the hardware PWM is, can you elaborate? (like using analogWrite?)
Makes sense to include the schematic too. Will slap something together in Photoshop
You caught the part that I had trouble with and took a while to debug.
The pins array has just one value so the pin count variable should be 1 instead of 2, but the moment I set that value to 1, the color would fade out but not back in. Somehow defining a count of 2 would suppress the issue, and I left it that way.
Turns out the bug is caused by the portion where I told handlePWM to ignore all blinking logic if the brightness is at 100 or zero. During the 5 seconds where brightness is at 100 or 0, It omits the logic but the TickCounter kept incrementing. So by the time it resume the logic, TickCounter had ran away and became a negative value and screwed everything up.
And of course if there's only one pin I really should get rid of the array and loops, though I have a lighted tree topper and I might add another pin later.
All those nasty issues are fixed, and the fading is nice and smooth now. Thanks for looking over the code!
Yeah, you can do that if you connect them to the same timer. I would use timer1 or timer2 for that so you can also increase the PWM frequency. If you connect it to pin 9 and pin 10 you can use the following in setup:
TCCR1A = (TCCR1A & 0b00001111) | COM1A1 | COM1B1 | COM1B0; //makes the two outputs inverse
TCCR1B = (TCCR1B & 0b11111000) | 0x02; //sets PWM frequency to 3,9kHz
Now if you set pin 9 and 10 to the same duty cycle (via analogWrite()) they will be each others inverse.