Here's the modified code, the color change is working now but the fading LED just stays solid, it stays at a certain brightness depending on the value of fadeamount.
Edit: I forgot to put a delay, it's all working now.
const int fadingled = 9; //fading led pin
int brightness = 1; //brightness of the led
int fadeamount = 1; //how much the led fades
const int colorchange1 = 11; //red dual color pin
const int colorchange2 = 12; //green dual color pin
int colorledstate1 = LOW; //red led state on/off
int colorledstate2 = LOW; //green led state on/off
long previousmillis = 0; //last time LED was updated
long interval = 500; //time between flashes
void setup() {
pinMode(fadingled,OUTPUT); //declare all LED's as outputs
pinMode(colorchange1,OUTPUT);
pinMode(colorchange2,OUTPUT);
}
void loop() {
digitalWrite(colorchange1,colorledstate1); //write to the LED's
digitalWrite(colorchange2,colorledstate2);
analogWrite(fadingled, brightness); //set the brightness to the LED
brightness = brightness += fadeamount; //add or subtract to the brightness based on fadeamount
if (brightness == 0 || brightness == 255) {
fadeamount = -fadeamount;
}
unsigned long currentmillis = millis();
if (currentmillis - previousmillis > interval) { //if it has been more than 500 milliseconds
previousmillis = currentmillis;
//turn the led off if it's on and vice versa
if (colorledstate1 == LOW) {
colorledstate1 = HIGH; }
else {
colorledstate1 = LOW; }
//if the red LED is on, turn the green LED off and vice versa
if (colorledstate1 == LOW) {
colorledstate2 = HIGH;
}
else {
colorledstate2 = LOW;
}
}
}