Go Down

Topic: Using PWM pins for digital & analog writes alternately? (Read 862 times) previous topic - next topic

Andy_Cool

Hi

Suppose I use Arduino Uno to build a 3x3x3 LED cube. The patterns would
be displayed using the digitalWrite() function.
The PWM pins would be assigned to 6 of the 9 columns on each of
the 3 layers. Can I employ these pins to intermittently use the analogWrite()
function, so as to fade-in & out at least 6 of the 9 LED's on each layers?

In short, can I employ the PWM pins to use the digitalWrite() & analogWrite()
functions alternately for on/off & fade-in/out respectively on 6 LEDS of each of
the 3 layers?

Thank you :)

johnwasser

You can switch between analogWrite() and digitalWrite() as frequently as you like.

One problem with using PWM pins to drive the columns of a multiplexed display is that the multiplex frequency (the rate of switching between rows) might be close to a multiple of the PWM frequency.  If so you'll get a throbbing or blinking effect rather than a constant dimmer value.
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Andy_Cool

Oh so that means if I want to drive 5 columns using the PWM (common anode to each pwm),
it wont have the desired effect of the columns fading in & out but would strobe/blink.
That sucks. :-) Thanks John for letting me know why!

johnwasser

You can do PWM in software such that it will be synchronized with the multiplexing process.  This take a good deal more programming but it lets you fade individual LED's in any combination.
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Go Up