我需要弄清楚如何在使用 Arduino 的函数中淡入和淡出多个 LED。不能使用 delay() ,因为其他东西需要在光线变暗时运行。到目前为止,这是它所拥有的,但不起作用。
int value = 0; // variable to keep the actual value
int ledpin = 9; // light connected to digital pin 9
int p1 = 0;
void setup()
{
// nothing for setup
Serial.begin(9600);
}
void loop()
{
inout(50, 30, 9, 0, 0);
//inout(20, 20, 10);
}
void inout(int inDelay, int outDelay, int ledpin, long previousmil, int done)
{
if(millis() - previousmil>inDelay){
if (value <=255){
analogWrite(ledpin, value); // sets the value (range from 0 to 255)
value+=5;
}
previousmil=millis();
}
if(value = 260)
done = 1;
if(millis() - previousmil>outDelay && done == 1){
if (value >0){
analogWrite(ledpin, value); // sets the value (range from 0 to 255)
value-=5;
}
previousmil=millis();
}
}