|
急 写一个ardunio 程序 不知道为什么后面的case一直没反应
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
while(Serial.read()>= 0){};
pinMode(2, INPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(13, OUTPUT);
if (Serial.available()>0 ) {
digitalWrite(13, LOW);
delay(3000);
digitalWrite(13, HIGH);
}
}
void loop() {char i = Serial.read();
switch(i)
{
case'a':
Serial.flush();
int analogInputVal = analogRead(A0);
Serial.println(analogInputVal);
break;
case'b':
Serial.println(121);
int ser = Serial.read()*1000;
digitalWrite(4, HIGH);
delay(ser);
digitalWrite(4, LOW);
break;
case'c':
digitalWrite(5, HIGH);
delay(5000);
digitalWrite(5, LOW);
delay(1000);
int CLEAN = digitalRead(2);
Serial.println(CLEAN);
break;
case'd':
digitalWrite(6, HIGH);
delay(5000);
digitalWrite(6, LOW);
delay(1000);
digitalWrite(4, HIGH);
delay(5000);
digitalWrite(4, LOW);
digitalWrite(5, HIGH);
delay(3000);
digitalWrite(5, LOW);
Serial.println(CLEAN);
break;
case'e':
digitalWrite(6, HIGH);
delay(5000);
digitalWrite(6, LOW);
break;
}
Serial.flush();
}
代码case 判断 a 正常 bcde 一直无反应这是为什么
|
|