Hello,
I am having a strange problem…
I am trying to upload code to a non-official mega. However, it times out. If I try to load the blink sketch, that will load fine. I was able to narrow the problem down to this section of code:
void christmasTwinkle() {
zSpeed = 100;
int ranamount = 1000; // The higher the number, lowers the chance for a pixel to light up. // Standard delay value in milliseconds.
byte fadeval = 255; // Fade rate
static byte color;
static boolean justonce;
// Make sure we're at least utilizing ALL the LED's.
int idex = random16(0, ranamount);
if (idex < NUM_LEDS) { // Only the lowest probability twinkles will do.
byte value = random(100, 255);
byte saturation = random();
if (color == 0) {
color = 96;
}
else color = 0;
if(idex < NUM_LEDS && idex > 0){
leds[idex] = CHSV(color, saturation, value);
}
if((idex + 1) < NUM_LEDS && (idex + 1) > 0){
leds[idex + 1] = CHSV(color, saturation, value);
}
}
if (zFlag == 1 && justonce == 1) {
justonce = 0;
for (int i = 0; i < NUM_LEDS; i++) {
leds[i].nscale8(fadeval); // Go through the array and reduce each RGB value by a percentage.
if((i + 1) < NUM_LEDS && (i + 1) > 0){
leds[i + 1].nscale8(fadeval);
}
}
} else if (zFlag == 0) {
justonce = 1;
}
}
If i comment this out, the sketch will compile fine… Which is strange, since i have this function right above it, which performs the same action but just in different colors…
void patrioticTwinkle() {
zSpeed = 100;
int ranamount = 1000; // The higher the number, lowers the chance for a pixel to light up. // Standard delay value in milliseconds.
byte fadeval = 255; // Fade rate
static byte color;
static boolean justonce;
//if (ranamount >NUM_LEDS) ranamount = NUM_LEDS; // Make sure we're at least utilizing ALL the LED's.
int idex = random16(0, ranamount);
if (idex < NUM_LEDS) { // Only the lowest probability twinkles will do.
byte value = random(100, 255);
byte saturation = random();
if (color == 160) {
color = 0;
}
else color = 160;
if(idex < NUM_LEDS && idex > 0){
leds[idex] = CHSV(color, saturation, value);
}
if((idex + 1) < NUM_LEDS && (idex + 1) > 0){
leds[idex + 1] = CHSV(color, saturation, value);
}
}
if (zFlag == 1 && justonce == 1) {
justonce = 0;
for (int i = 0; i < NUM_LEDS; i++) {
leds[i].nscale8(fadeval); // Go through the array and reduce each RGB value by a percentage.
if((i + 1) < NUM_LEDS && (i + 1) > 0){
leds[i + 1].nscale8(fadeval);
}
}
} else if (zFlag == 0) {
justonce = 1;
}
}
and this section of code doesn’t cause the IDE to timeout…
Any ideas? My entire code is below.