为什么我不需要那个?
你为什么不呢?
你当然知道。该程序使 LED 慢慢变亮,然后立即关闭,然后重新开始。那是锯齿形的轮廓,只是跛脚的IMO。
每个人都希望他们的 LED 平滑地变亮然后变暗。这更酷:
void setup() {
pinMode(13, OUTPUT);
}
boolean fadein = true;
int bright = 0;
void loop() {
// adjust brightness based on current direction
if(fadein) {
bright += 1;
}
else {
bright -= 1;
}
// apply current light level
analogWrite(13,bright);
// when get to full bright, turn around
if(255 == bright) {
fadein = false;
}
// when get to full off, turn around
if(0 == bright) {
fadein = true;
}
delay(10);
// The delay is just a placeholder
// here is where your program could do other useful things
// in addition to the cool LED fade in fade out
return;
}