Arduino入门实践之LED彩灯之呼吸灯

int redPin = 7;
int greenPin = 9;
int bluePin = 11;

void setup() {
  pinMode(redPin,OUTPUT);
  pinMode(greenPin,OUTPUT);
  pinMode(bluePin,OUTPUT);
}
void breath(int colorValue,int colorPin)
{
  for(int colorValue = 0;colorValue <= 255;colorValue += 5)
  {
    analogWrite(colorPin,colorValue);
    delay(30);
  }
  for(int colorValue = 255;colorValue >= 0;colorValue -= 5)
  {
    analogWrite(colorPin,colorValue);
    delay(30);
  }  
}

void loop()
{
  int redValue,greenValue,blueValue;
  breath(redValue,redPin);
  breath(greenValue,greenPin);
  breath(blueValue,bluePin);
}

  

原文地址:https://www.cnblogs.com/zhongllmm/p/14089642.html