关于pmw共阳极三色LED的延伸
加入了输入D以后可以关闭所有PWM输出,我发现为0时灯最亮,255是关闭。因为所有颜色都是累加的所以必须要复位后使用!书上117页代码如下:int i;
String inString="";
boolean stringComplete=false;
char LED=' ';
void setup()
{
Serial.begin(9600);
}
void loop(){
if(stringComplete){
if(LED=='A'){//RED
analogWrite(9,i);
}
else if(LED=='B'){//GREEN
analogWrite(10,i);
}
else if(LED=='C'){//BLUE
analogWrite(11,i);
}
else if(LED=='D'){//guan bi suo you deng.
analogWrite(9,255);analogWrite(10,255);analogWrite(11,255);
}
stringComplete=false;
inString="";
LED=' ';
}
}
void serialEvent(){
while(Serial.available()){
char inChar=Serial.read();
if (isDigit(inChar)){
inString+=inChar;
}
else if(inChar=='\n'){
stringComplete=true;
i=inString.toInt();
}
else LED=inChar;
}
}
页:
[1]