1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
#define LED_PIN 12
#define freq 2000
#define channel 0
#define resolution 8 //分辨率
void setup() {
// put your setup code here, to run once:
//pinMode(LED_PIN,OUTPUT);
ledcSetup(channel,freq,resolution);
ledcAttachPin(LED_PIN,channel);
}
void loop() {
// put your main code here, to run repeatedly:
for(int i=0;i<pow(2,resolution);i++) {
ledcWrite(channel,i);
delay(10);
}
for(int i=pow(2,resolution)-1;i>=0;i--) {
ledcWrite(channel,i);
delay(10);
}
}
|