I got a breadboard with 10 LEDs, 4 of them fade, to be specific: 3, 5, 6 and 9 are working. 0, 1, 2, 4, 7, 8 are not working.
I'm using LEDs and resistors on all spots, they're all the same. Tried changing things around but the problem doesn't seem to be the resistors or the LEDs.
I'm using the following code (I'll highlight the parts for the fading, by marking it between //**
comments).
Does anyone know a way to fix this? Or see any problem?
const int inButton = 13;
int buttonPushCounter = 0;
int buttonState = 0;
int lastButtonState = 0;
int delayTime = 100;
int brightness = 0;
int fadeAmount = 5;
void setup() {
//**
pinMode(inButton, INPUT);
for (int out = 0; out < 10; out++){
pinMode(out, OUTPUT);
}
//**
pinMode(testLed, OUTPUT);
}
void loop() {
buttonState = digitalRead(inButton);
if (buttonState != lastButtonState){
if (buttonState == 1){
buttonPushCounter++;
}
}
lastButtonState = buttonState;
if (buttonPushCounter % 5 == 0){
for (int i = 0; i < 10; i++){
digitalWrite(i, 1);
delay(delayTime / 2);
digitalWrite(i, 0);
}
}
else if (buttonPushCounter % 5 == 1){
for (int i = 0, j = 9; i < 10, j >= 0; i++, j--){
digitalWrite (i, 1);
digitalWrite (j, 1);
delay(delayTime / 2);
digitalWrite (i, 0);
digitalWrite (j, 0);
}
}
else if (buttonPushCounter % 5 == 2){
for (int i = 0; i < 10; i+=2){
digitalWrite(i, 1);
}
delay(delayTime);
for (int i = 0; i < 10; i+=2){
digitalWrite(i, 0);
}
delay(delayTime);
for (int i = 1; i < 10; i+=2){
digitalWrite(i, 1);
}
delay(delayTime);
for (int i = 1; i < 10; i+=2){
digitalWrite(i, 0);
}
}
else if (buttonPushCounter % 5 == 3){
for (int i = 0 ; i < 10 ; i++){
analogWrite(i, brightness);
}
brightness = brightness + fadeAmount;
if (brightness == 0 || brightness == 255){
fadeAmount = -fadeAmount;
}
delay(25);
}
else {
int R1 = random(10);
int R2 = random(10);
int R3 = random(10);
int R4 = random(10);
digitalWrite(R1, 1);
digitalWrite(R2, 1);
digitalWrite(R3, 1);
digitalWrite(R4, 1);
delay(delayTime);
digitalWrite(R1, 0);
digitalWrite(R2, 0);
digitalWrite(R3, 0);
digitalWrite(R4, 0);
}
}