如何使用arduino使led褪色?
我对arduino有意见。当我尝试使用以下代码使LED褪色时:如何使用arduino使led褪色?,arduino,fading,Arduino,Fading,我对arduino有意见。当我尝试使用以下代码使LED褪色时: int led = 9; // the PWM pin the LED is attached to int brightness = 0; // how bright the LED is int fadeAmount = 5; // how many points to fade the LED by void setup() { // declare pin 9 to be an
int led = 9; // the PWM pin the LED is attached to
int brightness = 0; // how bright the LED is
int fadeAmount = 5; // how many points to fade the LED by
void setup() {
// declare pin 9 to be an output:
pinMode(led, OUTPUT);
}
// the loop routine runs over and over again forever:
void loop() {
// set the brightness of pin 9:
analogWrite(led, brightness);
// change the brightness for next time through the loop:
brightness = brightness + fadeAmount;
// reverse the direction of the fading at the ends of the fade:
if (brightness <= 0 || brightness >= 255) {
fadeAmount = -fadeAmount;
}
// wait for 30 milliseconds to see the dimming effect
delay(30);
}
int led=9;//LED连接到的PWM引脚
int亮度=0;//LED多亮啊
int fadeAmount=5;//有多少点可以使LED变暗
无效设置(){
//将引脚9声明为输出:
引脚模式(led,输出);
}
//循环例程会一直反复运行:
void循环(){
//设置针脚9的亮度:
模拟写入(led,亮度);
//通过循环更改下一次的亮度:
亮度=亮度+fadeAmount;
//在淡入淡出的末端反转淡入淡出的方向:
如果(亮度=255){
fadeAmount=-fadeAmount;
}
//等待30毫秒以查看变暗效果
延误(30);
}
这行不通
这是我工作的照片:
你们能帮忙吗