Hello everybody,
I am running this code:
/*
Fade
This example shows how to fade an LED on pin 9
using the analogWrite() function.
This example code is in the public domain.
*/
int leds[] = {2, 3, 4, 5, 6, 7}; // the pin that the LED is attached to
int brightness[] = {0, 0, 0, 0, 0, 0}; // how bright the LEDs are
int fadeAmount = 5; // how many points to fade the LED by
int a = 0; // zaehlvariable
// the setup routine runs once when you press reset:
void setup() {
// declare pin 2-7 to be an output:
for (int x = 2; x < 8; x++){
pinMode(x, OUTPUT);
}
}
// the loop routine runs over and over again forever:
void loop() {
if (a == 7){
a = 0;
}
// set the brightness
analogWrite(leds[a], brightness[a]);
// change the brightness for next time through the loop:
brightness[a] = brightness[a] + fadeAmount;
// reset the brightness at the end of the fade:
if (brightness[a] == 255) {
brightness[a] = 0;
}
a = a + 1;
// wait to see the dimming effect
delay(10);
}
and it works perfectly fine and as intended, however if I change the start values of the brightness array to for example:
brightness[] = {0, 50, 100, 150, 200, 250}
it won't work any more. All the Leds fade to as bright as possible and nothing else happens. I tried to get the values through the serial monitor but what I get is very confusing. I get the proper values with some strange numbers inbetween:
5
5
5
5
5
6
526969
10
10
10
10
10
6
526969
15
15
15
15
15
6
526969
20
20
20
20
20
6
526969
etc..
And when I change the brightness values slightly I get numbers like these:
2
165
165
155
255
155
160
2
325
325
315
415
assertion "duty <= pPwm->PWM_CH_NUM[ul_channel].PWM_CPRD" failed: file "../source/pwmc.c", line 272, function: PWMC_SetDutyCycle
Exiting with status 1.
Which produce the error above (I guess the numbers are too high but I don't get it why).
I am using an Arduino Due with the 1.5.2 IDE
Tim