Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Animation 为rgb led arduino创建灯光动画_Animation_Arduino_Led - Fatal编程技术网

Animation 为rgb led arduino创建灯光动画

Animation 为rgb led arduino创建灯光动画,animation,arduino,led,Animation,Arduino,Led,我正在用rgb做一个arduino控制的灯。我试图在led发光的每种颜色之间添加平滑过渡。我不希望频道单独设置动画。目前,它一次只能使用一个通道,只有当亮度增加时,传输才起作用 const int redpin = 9; const int greenpin = 10; const int bluepin = 11; int currRed = 0; int currGreen = 0; int currBlue = 0; int dur

我正在用rgb做一个arduino控制的灯。我试图在led发光的每种颜色之间添加平滑过渡。我不希望频道单独设置动画。目前,它一次只能使用一个通道,只有当亮度增加时,传输才起作用

    const int redpin = 9;
    const int greenpin = 10;
    const int bluepin = 11;
    int currRed = 0;
    int currGreen = 0;
    int currBlue = 0;
    int dur = 1000;

    void setup() {
      pinMode(redpin, OUTPUT);
      pinMode(greenpin, OUTPUT);
      pinMode(bluepin, OUTPUT);
      Serial.begin(9600);
    }

    void loop() {
      if (Serial.available()) {
      int red = Serial.parseInt();
      int green = Serial.parseInt();
      int blue = Serial.parseInt();

      if (Serial.read() == '\n') {
        red = constrain(red, 0, 255);
        green = constrain(green, 0, 255);
        blue = constrain(blue, 0, 255);
        }

      updateRGBfade(redpin, red, dur, currRed);
      updateRGBfade(greenpin, green, dur, currGreen);
      updateRGBfade(bluepin, blue, dur, currBlue);
      }
    }



   void updateRGBfade(int pin, int col, int animdur, int currcol) {
      if (col > currcol) {
        for (int setto = currcol; setto < col; setto++) {
          analogWrite(pin, setto);
          delay(5);
        }
      }
      if (col < currcol) {
        for (int setto = currcol; setto > col; setto=setto-1) {
          analogWrite(pin, setto);
          delay(5);
        }
      }
    }
const int redpin=9;
常数int格林平=10;
常数int bluepin=11;
int curred=0;
绿色=0;
蓝色=0;
int-dur=1000;
无效设置(){
引脚模式(红色引脚,输出);
引脚模式(绿色引脚,输出);
引脚模式(蓝引脚,输出);
Serial.begin(9600);
}
void循环(){
if(Serial.available()){
int red=Serial.parseInt();
int绿色=Serial.parseInt();
int blue=Serial.parseInt();
如果(Serial.read()='\n'){
红色=约束(红色,0,255);
绿色=约束(绿色,0,255);
蓝色=约束(蓝色,0,255);
}
updateRGBfade(红色、红色、dur、咖喱色);
updateRGBfade(绿色、绿色、dur、currGreen);
updateRGBfade(蓝针、蓝色、dur、currBlue);
}
}
void updateRGBfade(int pin、int col、int animdur、int currcol){
如果(列>当前列){
for(int setto=currcol;settocol;setto=setto-1){
模拟写入(引脚,设置到);
延误(5);
}
}
}
咖喱色(咖喱红、咖喱绿和咖喱蓝)为常量,等于零。所以updateRGBfade函数只在阻塞时首先运行,因为currcol始终为零,我认为通常情况下col大于零。所以函数只运行递增过程。如果模块延迟(5)s以下,则可以在函数中添加以下行


很抱歉我的英语不好。

我现在已经上传了这段代码,但仍然可以正常工作
if(pin == redpin){
currRed = currcol;
}else if(pin == greenpin){
currGreen = currcol;
}else if(pin == bluepin ){
currBlue = currcol;
}