Solved: The darn led was backwards... No idea how that happened...
In the following code, all of the Leds work fine... Except for the 3rd one. On the 3rd led, the first and third pot are switched. The first controlls red normally, and blue on the third led. The third pot controlls blue normally, and red on the third led.
Also, the green (middle) pot doesn't do anything on the 3rd led.
const byte Red[4] = {13, 10, 7, 4};
const byte Green[4] = {12, 9,6, 3};
const byte Blue[4] = {11, 8,5, 2};
int backButton = 14;
int forwardButton = 15;
int redPot = 0;
int greenPot = 1;
int bluePot = 2;
int backState;
int forwardState;
int previousBack;
int previousForward;
int redVal;
int greenVal;
int blueVal;
int LED;
void setup(){
for (int i = 0; i < sizeof(Red) / sizeof(Red[0]); ++i) {
pinMode (Red[i], OUTPUT);
}
for (int i = 0; i < sizeof(Green) / sizeof(Green[0]); ++i) {
pinMode (Green[i], OUTPUT);
}
for (int i = 0; i < sizeof(Blue) / sizeof(Blue[0]); ++i) {
pinMode (Blue[i], OUTPUT);
}
pinMode(backButton, INPUT);
pinMode(forwardButton, INPUT);
digitalWrite(backButton, HIGH);
digitalWrite(forwardButton, HIGH);
}
void loop(){
backState = digitalRead(backButton);
forwardState = digitalRead(forwardButton);
if(backState == LOW && previousBack == HIGH){
LED = LED-1;
}
else{
}
if(forwardState == LOW && previousForward == HIGH){
LED = LED+1;
}
else{
}
if(LED == 5){
LED = 1;
}
if(backState == LOW && forwardState == LOW){
for (int i = 0; i < sizeof(Red) / sizeof(Red[0]); ++i) {
digitalWrite(Red[i], LOW);
}
for (int i = 0; i < sizeof(Green) / sizeof(Green[0]); ++i) {
digitalWrite(Green[i], LOW);
}
for (int i = 0; i < sizeof(Blue) / sizeof(Blue[0]); ++i) {
digitalWrite(Blue[i], LOW);
}
}
redVal = analogRead(redPot);
greenVal = analogRead(greenPot);
blueVal = analogRead(bluePot);
map(redVal, 0, 1023, 0, 255);
map(greenVal, 0, 1023, 0, 255);
map(blueVal, 0, 1023, 0, 255);
analogWrite(Red[LED], redVal);
analogWrite(Green[LED], greenVal);
analogWrite(Blue[LED], blueVal);
previousBack = backState;
previousForward = forwardState;
}