Hi all,
since i'm going to use an arduino only for providing 6 pwm signal, i'm curious if is possible to do this without using the conventional pwm pins (that generates pwm via the analogWrite)
after all the pwm signals are a faster hight/low alternate, so why not ?
i try to write something using delay function but wasn't a great idea, i'm sure that out there there is something that handle this before me, if yes, any suggestion (the difficult part is to keep all the 6 signal going on while i'm upgrading the pwm value of each one).
It depends on exactly how perfect you want your PWM to be. If you're willing to have a "gap" when all your pins are either on or off (and you update the pwm values), it's pretty trivial. Here's the core of some code that was used to generate 5 pins worth of random brightness on some LEDs for a "flame" effect. (It's not actually arduino code, but it should covert pretty easilly.)
while (1) { // forever
getbright();
for (level_delay = 50; level_delay != 0; level_delay--) {
pwm1 = bright1;
pwm2 = bright2;
pwm3 = bright3;
pwm4 = bright4;
pwm5 = bright5;
led_all_on();
for (pwm_delay = 128; pwm_delay !=0; pwm_delay--) {
/*
* We have a random number in each PWM between 1 and 128
* and we're going to have 128 cycles of delay. So each
* decremented output can only cross zero once, at which
* time we toggle the output state.
*/
if (--pwm1 == 0) {
led1_off;
}
if (--pwm2 == 0) {
led2_off;
}
if (--pwm3 == 0) {
led3_off;
}
if (--pwm4 == 0) {
led4_off;
}
if (--pwm5 == 0) {
led5_off;
}
} /* time for new PWM cycle */
} /* time for new brightness */
} /* while forever */