#include <Arduino.h>
// 硬件配置
const int LED_PIN = 2; // 使用内置LED(通常为GPIO2)
const int UART_TX_PIN = 1; // UART发送引脚(根据实际硬件调整)
const unsigned long BAUD_RATE = 9600;
// 全局变量
unsigned long startTime = 0;
int currentBrightness = 0;
enum Phase { INCREASE, PAUSE, DECREASE };
Phase currentPhase = INCREASE;
void setup() {
Serial.begin(BAUD_RATE);
pinMode(LED_PIN, OUTPUT);
Serial.println("System initialized");
}
void loop() {
switch (currentPhase) {
case INCREASE:
Serial.println("INCREASE_PHASE STARTED");
for (int i = 0; i <= 100; i += 10) {
currentBrightness = i;
analogWrite(LED_PIN, map(currentBrightness, 0, 100, 0, 255)); // 将百分比转为0-255
delay(1000); // 每秒增加一次亮度
}
currentPhase = PAUSE;
break;
case PAUSE:
Serial.println("PAUSE_PHASE STARTED");
delay(10000); // 暂停10秒
currentPhase = DECREASE;
break;
case DECREASE:
Serial.println("DECREASE_PHASE STARTED");
for (int i = 100; i >= 0; i -= 10) {
currentBrightness = i;
analogWrite(LED_PIN, map(currentBrightness, 0, 100, 0, 255));
delay(1000);
}
currentPhase = PAUSE;
break;
}
}