LED Fading

MiniPOV4 and previous versions

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
rbpuppy1
 

LED Fading

Post by rbpuppy1 »

Hello,

I've just ordered a few kits but wanted to do some research... what kind of modifications would it take to be able to program the led's brightness to make them fade in and out for dynamic effects? Thanks

vik
 
Posts: 6
Joined: Sat Feb 18, 2006 2:18 am

Post by vik »

It should be possible to use pulse width modulation on the output lines if the processor is fast enough to acheive that effect. i.e. rather than providing the voltage to the LED continuously, cut it on and off very quickly.

And I saw some sample code for anti-aliasing on the site somewhere - this would have to use a similar effect.

kragen
 
Posts: 21
Joined: Sat Mar 12, 2005 4:55 am

Post by kragen »

This is somewhat suboptimal but should pretty much work:

Code: Select all

#include <avr/io.h>      // this contains all the IO port definitions

void brightness(unsigned char on_time, unsigned char pattern) {
    unsigned long int ii;
    unsigned char timer;
    for (ii = 0; ii < 80; ii++) {
        PORTB = pattern;
        for (timer = 0; timer <= on_time; timer++);
        PORTB = 0x00;
        while (timer) timer++;
    }
}

int main(void) {
    unsigned char on_time;
    unsigned char pattern = 1;

    DDRB = 0xFF;        // set port B to output only

    while (1) {
        for (on_time = 1; on_time < 200; on_time += 1 + (on_time >> 4)) {
            brightness(on_time, pattern);
        }
        for (on_time = 200; on_time > 0; on_time -= 1 + (on_time >> 4)) {
            brightness(on_time, pattern);
        }
        pattern++;
    }
}

kragen
 
Posts: 21
Joined: Sat Mar 12, 2005 4:55 am

Post by kragen »

Also the ATtiny2313 has PWM output driven by a specialized PWM driver, but I don't remember if you can get that guy to talk to the pins that are connected to the LEDs. I think his primary advantage is that you can (a) do something more important than count clock cycles for PWM and (b) do it when the CPU is in idle or power-down mode to reduce power consumption.

pupdawg
 
Posts: 7
Joined: Thu Feb 23, 2006 1:16 pm

Brightness

Post by pupdawg »

I would love to be able to control the brightness separate for each LED for mixing colors... 3 LEDs R G B and control there brightness to mix there colors.

kragen wrote:Also the ATtiny2313 has PWM output driven by a specialized PWM driver, but I don't remember if you can get that guy to talk to the pins that are connected to the LEDs. I think his primary advantage is that you can (a) do something more important than count clock cycles for PWM and (b) do it when the CPU is in idle or power-down mode to reduce power consumption.

kragen
 
Posts: 21
Joined: Sat Mar 12, 2005 4:55 am

Re: Brightness

Post by kragen »

pupdawg wrote:I would love to be able to control the brightness separate for each LED for mixing colors... 3 LEDs R G B and control there brightness to mix there colors.
Well, connect one output pin to R, one to G, and one to B, and you can do that. Check the specs on the B first --- does it require a higher voltage?

Also, generally the 3-color LEDs have four leads, not six, so you may have to build a different circuit depending on whether it's common-cathode or common-anode.

pupdawg
 
Posts: 7
Joined: Thu Feb 23, 2006 1:16 pm

Re: Brightness

Post by pupdawg »

Yea the blue LED's I have use higher voltage.... I'm very very new to all this electronic stuff my background is in software devel. What I want to do it use ultra bright white LEDs with gels to make them colored and then use the tiny to do color mixing and other effects. I've managed to connect the tiny to terminal emulator and I am now writing a menu driven system for the LED's

kragen wrote:
pupdawg wrote:I would love to be able to control the brightness separate for each LED for mixing colors... 3 LEDs R G B and control there brightness to mix there colors.
Well, connect one output pin to R, one to G, and one to B, and you can do that. Check the specs on the B first --- does it require a higher voltage?

Also, generally the 3-color LEDs have four leads, not six, so you may have to build a different circuit depending on whether it's common-cathode or common-anode.

Locked
Please be positive and constructive with your questions and comments.

Return to “MiniPOV”