Untitled

三色led
mail@pastecode.io avatar
unknown
plain_text
2 years ago
1.4 kB
4
Indexable
Never
//threeColorLED.ino
#define led_red D0     //D0 連接上 led的紅色引腳
#define led_green D1
#define led_blue D2


void setup() {
  pinMode(led_red,OUTPUT);  //設置爲輸出模式
  pinMode(led_green,OUTPUT);
  pinMode(led_blue,OUTPUT);
  
  analogWrite(led_red,0);     //首先,先把所有的燈都關閉
  analogWrite(led_green,0);   //可以隨意設置開啓關閉哪些燈,搭配出不同組合有不同顏色
  analogWrite(led_blue,255);
  delay(10000);
}

void loop() {
  // put your main code here, to run repeatedly:
  
     analogWrite(led_red,200);
     analogWrite(led_green,0);
     analogWrite(led_blue,0);
     delay(2000);
     analogWrite(led_red,0);
     analogWrite(led_green,200);
     analogWrite(led_blue,0);
     delay(2000);
     analogWrite(led_red,0);
     analogWrite(led_green,0);
     analogWrite(led_blue,200);
     delay(2000);
//  for(int i=200;i>0;i--)      //漸亮
//  {
//    analogWrite(led_red,i);     //慢慢開啓紅色和綠色會搭配出黃色
//    analogWrite(led_green,i);  
//    analogWrite(led_blue,255);  
//    delay(10);
//  }
//
//  for(int i=0;i<200;i++)   //漸滅
//  {
//    analogWrite(led_red,255);    //慢慢關閉綠色和藍色會搭配出較鮮豔的藍色
//    analogWrite(led_green,i);
//    analogWrite(led_blue,i);
//    delay(10);
//  }
  
}