奔跑的二毛 发表于 2014-9-30 23:28:48

i7456 发表于 2014-9-30 17:15 static/image/common/back.gif
analogRead(5)/4;
把analogRead()的值除以4,analogRead()范围是0-1023,analogWrite()的范围是0-255;
...

谢谢你~
int redPin = 11;
int greenPin = 10;
int bluePin = 9
int value = 0;
这里不用写 in potPin =5 吗?就是电位计输入的那个脚。

setColor(value, 70, 80)这个的话我改了70,80,什么数值出来灯的效果都一样啊。
都是从偏紫的红到蓝色。 这个是改变了红色通道吗?

奔跑的二毛 发表于 2014-10-1 00:24:27

i7456 发表于 2014-9-30 17:15 static/image/common/back.gif
analogRead(5)/4;
把analogRead()的值除以4,analogRead()范围是0-1023,analogWrite()的范围是0-255;
...

int redPin = 11;
int greenPin = 10;
int bluePin = 9;
int a = 0;
int b = 0;
int c = 0;

void setup()
{
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
}

void loop()
{
      a = analogRead(0)/4;
      setColor(a,0,0);//hong
      b= analogRead(5)/4;
      setColor(0,b,0);// lü
      c = analogRead(2)/4;
      setColor(0,0,c);// lan
      
      
      
      
}

void setColor(int red, int green, int blue)
{
//analogWrite(redPin, 255-red);
analogWrite(greenPin, 255-green);
analogWrite(bluePin, 255-blue);
}

这是我用三个电位器做的共同调节RGB灯的代码,出来还是淡淡的紫色,我检查过线路没问题的,是代码有问题吗?

bonarm 发表于 2014-10-1 00:28:22

你不需要调亮度吧?那就不要用analogWrite,用digitalWrite直接控制开关就行了。

i7456 发表于 2014-10-1 12:01:06

奔跑的二毛 发表于 2014-10-1 00:24 static/image/common/back.gif
int redPin = 11;
int greenPin = 10;
int bluePin = 9;
int redPin = 11;
int greenPin = 10;
int bluePin = 9;
int a = 0;
int b = 0;
int c = 0;

void setup()
{
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
}

void loop()
{
      a = analogRead(0)/4;
      b = analogRead(5)/4;
      c = analogRead(2)/4;
      setColor(a,b,c);         
}

void setColor(int red, int green, int blue)
{
analogWrite(redPin, 255-red);
analogWrite(greenPin, 255-green);
analogWrite(bluePin, 255-blue);
}

topdog 发表于 2014-10-2 21:00:04

哈哈,笑死人。
页: 1 [2]
查看完整版本: 用电位器调RGB灯的颜色,请问我这个出现什么错误了?