Quantcast
Channel: Arduino Forum - Latest topics
Viewing all articles
Browse latest Browse all 15427

Why doesn't this two-LED fade work?

$
0
0
int redLED = 9;
int yellowLED = 3;         
int redBrightness = 0;  
int yellowBrightness = 255;
int fadeAmount = 5;  

void setup() {
  pinMode(redLED, OUTPUT);
  pinMode(yellowLED, OUTPUT);
}

void loop() {
  analogWrite(redLED, redBrightness);
  analogWrite(yellowLED, yellowBrightness);
  
  if (redBrightness == 0){
    delay(500);
    redBrightness = redBrightness + fadeAmount;
  }

    if (yellowBrightness == 0){
    delay(500);
  }

  yellowBrightness = yellowBrightness - fadeAmount;
  redBrightness = redBrightness + fadeAmount;

  if (redBrightness <= 0 || redBrightness >= 255) {
    fadeAmount = -fadeAmount;
  }
  
  delay(5);
}

3 posts - 3 participants

Read full topic


Viewing all articles
Browse latest Browse all 15427

Trending Articles