|
写程序的时候想着先能控制一个固定亮度,然后成功了,但是另外两档亮度加上去后就不行了
这是可以控制一档固定亮度的代码:
int brightness; //LED亮度变量
int serialData; //串口数据变量
void setup() {
Serial.begin(9600);
pinMode(LED_BUILTIN, OUTPUT);
pinMode(11, OUTPUT);
}
void loop(){analogWrite(11,brightness);
if( Serial.available()>0 ){
serialData = Serial.parseInt();
Serial.print("serialData = "); Serial.println(serialData);
if (serialData >=0 && serialData <= 255) {
if (serialData = 1){
for (brightness; brightness <= 255; brightness=85){
analogWrite(11, brightness);
Serial.print("serialData = "); Serial.println(brightness);
delay(5);
}
}
}
}
}
然后把另外两档加上去就不行了:
int brightness; //LED亮度变量
int serialData; //串口数据变量
void setup() {
Serial.begin(9600);
pinMode(LED_BUILTIN, OUTPUT);
pinMode(11, OUTPUT);
}
void loop(){analogWrite(11,brightness);
if( Serial.available()>0 ){
serialData = Serial.parseInt();
Serial.print("serialData = "); Serial.println(serialData);
if (serialData >=0 && serialData <= 255) {
if (serialData = 1){
for (brightness; brightness <= 255; brightness=85){
analogWrite(11, brightness);
if (serialData = 2){
for (brightness; brightness <= 255; brightness=175) if (serialData = 3){
for (brightness; brightness <= 255; brightness=255) Serial.print("serialData = "); Serial.println(brightness);
delay(5);
}
}
}
}
}}}
求大神指点! |
|