Hi
I like the SoftPWM-library for arduino a lot. Just today I found out, that millis() stops working, as soon as more than 4 LEDs are controlled using our library. I wasn't able to find a solution to that problem. Do you have an idea?
I just realized that the problem only occurs when I use the Lilypad ATMEGA 328.
On a Teensy++ 2.0, a Duemilanove with ATMEGA 328 or a ATMEGA 32U4, it works as expected, millis() increment. Any idea, what is different with the processor on the Lilypad?
Best regards,
Dani
I used your example-code (SoftPWM_LEDHead_Bounce), which uses 8 LEDs:
When checking with the serial monitor, I get constantly
26
26
26
which shows, that millis() is not incrementing.
Here is the code that doesn't work:
#include <SoftPWM.h>
#define DELAY 100
uint8_t leds[8] = {11,12,13,18,17,16,15,10};
void setup()
{
Serial.begin(57600);
SoftPWMBegin();
for (int i = 0; i < 8; i++)
SoftPWMSet(leds[i], 0);
SoftPWMSetFadeTime(ALL, 50, 400);
}
void loop()
{
int i;
Serial.println(millis());
for (i = 0; i < 7; i++)
{
SoftPWMSet(leds[i+1], 255);
SoftPWMSet(leds[i], 0);
delay(DELAY);
}
delay(400);
for (i = 7; i > 0; i--)
{
SoftPWMSet(leds[i-1], 255);
SoftPWMSet(leds[i], 0);
delay(DELAY);
}
delay(400);
}
As soon as I change the code, so that it uses only 4 LEDs, it works as expected:
3014
5851
8695
...millis() is incrementing as expected.
Here is the code that works:
#include <SoftPWM.h>
#define DELAY 100
uint8_t leds[8] = {11,12,13,18,17,16,15,10};
void setup()
{
Serial.begin(57600);
SoftPWMBegin();
for (int i = 0; i < 4; i++)
SoftPWMSet(leds[i], 0);
SoftPWMSetFadeTime(ALL, 50, 400);
}
void loop()
{
int i;
Serial.println(millis());
for (i = 0; i < 3; i++)
{
SoftPWMSet(leds[i+1], 255);
SoftPWMSet(leds[i], 0);
delay(DELAY);
}
delay(400);
for (i = 3; i > 0; i--)
{
SoftPWMSet(leds[i-1], 255);
SoftPWMSet(leds[i], 0);
delay(DELAY);
}
delay(400);
}