Arduino RGB LED小灯

int RED_PIN = 11; // RGB LED R管脚11
int GREEN_PIN = 12; //RGB LED G管脚12
int BLUE_PIN = 13; // RGB LED B管脚13
 
void setup() { 
  pinMode(RED_PIN, OUTPUT); //设置管脚11为输出状态
  pinMode(GREEN_PIN, OUTPUT); //设置管脚12为输出状态
  pinMode(BLUE_PIN, OUTPUT); //设置管脚13为输出状态
}
 
void loop() { 
  //熄灭
  digitalWrite(RED_PIN, LOW); 
  digitalWrite(GREEN_PIN, LOW); 
  digitalWrite(BLUE_PIN, LOW);  
  delay(1000); //等待1000毫秒
 
  //红色
  digitalWrite(RED_PIN, HIGH); 
  digitalWrite(GREEN_PIN, LOW); 
  digitalWrite(BLUE_PIN, LOW);
  delay(1000); //等待1000毫秒
  
  //绿色
  digitalWrite(RED_PIN, LOW); 
  digitalWrite(GREEN_PIN, HIGH); 
  digitalWrite(BLUE_PIN, LOW); 
  delay(1000); //等待1000毫秒
 
  //蓝色
  digitalWrite(RED_PIN, LOW);
  digitalWrite(GREEN_PIN, HIGH); 
  digitalWrite(BLUE_PIN, HIGH);  
  delay(1000); //等待1000毫秒

  // 红色+蓝色
  digitalWrite(RED_PIN, HIGH);
  digitalWrite(GREEN_PIN, LOW); 
  digitalWrite(BLUE_PIN, HIGH); 
  delay(1000); //等待1000毫秒

  // 红色+绿色
  digitalWrite(RED_PIN, HIGH);
  digitalWrite(GREEN_PIN, HIGH); 
  digitalWrite(BLUE_PIN, LOW); 
  delay(1000); //等待1000毫秒


  // 绿色+蓝色
  digitalWrite(RED_PIN, LOW);
  digitalWrite(GREEN_PIN, HIGH); 
  digitalWrite(BLUE_PIN, HIGH); 
  delay(1000); //等待1000毫秒

  // 红色+绿色+蓝色
  digitalWrite(RED_PIN, HIGH);
  digitalWrite(GREEN_PIN, HIGH);  
  digitalWrite(BLUE_PIN, HIGH);  
  delay(1000); //等待1000毫秒
}

你可能感兴趣的:(Arduino RGB LED小灯)