// 定義 LED 接腳
#define LED1 13
#define LED2 12
#define LED3 14
// 定義 PWM 設定
const int freq = 5000;
const int ledChannel1 = 0;
const int ledChannel2 = 1;
const int ledChannel3 = 2;
const int resolution = 8;
void setup() {
// 設定 LED 接腳為輸出模式
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
pinMode(LED3, OUTPUT);
ledcSetup(ledChannel1, freq, resolution);
ledcSetup(ledChannel2, freq, resolution);
ledcSetup(ledChannel3, freq, resolution);
ledcAttachPin(LED1, ledChannel1);
ledcAttachPin(LED2, ledChannel2);
ledcAttachPin(LED3, ledChannel3);
}
void loop() {
//逐一呼吸燈亮起並熄滅
for (int i = 0; i < 3; i++) {
//依序點亮第 i 顆 LED
ledcWrite(ledChannel1, map(i, 0, 2, 0, 255));
delay(90);
ledcWrite(ledChannel2, map(i, 0, 2, 0, 255));
delay(90);
ledcWrite(ledChannel3, map(i, 0, 2, 0, 255));
delay(90);
//依序熄滅第 i 顆 LED
ledcWrite(ledChannel1, map(i, 0, 2, 255, 0));
delay(90);
ledcWrite(ledChannel2, map(i, 0, 2, 255, 0));
delay(90);
ledcWrite(ledChannel3, map(i, 0, 2, 255, 0));
delay(90);
}
}