Arduino实践:LED Blinking 流水灯

Arduino例程,环境: Arduino学习平台搭建配置方式(一)

  const int blueLED = 5;
  const int redLED = 6;
  const int greenLED = 9;
  int delayTime = 1000;
  int lightTime = 500;
  int brightness = 30;

void setup() {
  // put your setup code here, to run once:

  pinMode(redLED, OUTPUT);
  pinMode(blueLED, OUTPUT);
  pinMode(greenLED, OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:

  //蓝色LED 亮灭
  digitalWrite(blueLED, HIGH);
  delay(lightTime);
  digitalWrite(blueLED, LOW);
  delay(delayTime);

  //红色LED 亮灭
  digitalWrite(redLED, HIGH);
  delay(lightTime);
  digitalWrite(redLED, LOW);
  delay(delayTime);

  //绿色LED 亮灭
  digitalWrite(greenLED, HIGH);
  delay(lightTime);
  digitalWrite(greenLED, LOW);
  delay(delayTime);

  //蓝色LED 亮灭
  analogWrite(blueLED, brightness);
  delay(lightTime);
  analogWrite(blueLED, LOW);
  delay(delayTime);


  //红色LED 亮灭
  analogWrite(redLED, brightness);
  delay(lightTime);
  analogWrite(redLED, LOW);
  delay(delayTime);

  //绿色LED 亮灭
  analogWrite(greenLED, brightness);
  delay(lightTime);
  analogWrite(greenLED, LOW);
  delay(delayTime);
  
}