int color;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(4,OUTPUT);
pinMode(8,OUTPUT);
pinMode(12,OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
Serial.println("which color led you want to light?");
while(Serial.available()==0){
}
color = Serial.parseInt();
switch(color){
case 1:
digitalWrite(4,1);
digitalWrite(8,0);
digitalWrite(12,0);
case 2:
digitalWrite(4,0);
digitalWrite(8,1);
digitalWrite(12,0);
case 3:
digitalWrite(4,0);
digitalWrite(8,0);
digitalWrite(12,1);
default:
digitalWrite(4,1);
digitalWrite(8,1);
digitalWrite(12,1);
Serial.println("wrong input!");
}
}
arduino的一个小程序,输入不同数字亮不同的灯,为什么case判断不能用?
不管输入1或2或3都只执行默认。