萌新求助~~~~
这段代码每次运行到case3就不向下运行了,有时候还会卡在case2那一步,需要长按或者连击才能进行到case3。volatile int item = 0;
int i = 0;
int x = 0;
int y = 255;
void setup(){
item = 0;
for (int i = 2; i <= 4; i = i + (1)) {
pinMode(i, OUTPUT);
digitalWrite(i,HIGH);
}
pinMode(5, INPUT);
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
}
void Blink()
{
for (;; ) {
digitalWrite(2,HIGH);
digitalWrite(3,HIGH);
digitalWrite(4,HIGH);
delay(1000);
digitalWrite(2,LOW);
digitalWrite(3,LOW);
digitalWrite(4,LOW);
delay(1000);
}
}
void loop(){
if (digitalRead(5) == HIGH) {
item = item + 1;
delay(10);
}
switch (item) {
case 0:
for (i = 2; i <= 4; i = i + (1)) {
pinMode(i, OUTPUT);
digitalWrite(i,HIGH);
}
break;
case 1:
digitalWrite(2,LOW);
digitalWrite(3,HIGH);
digitalWrite(4,HIGH);
break;
case 2:
for (x = 0; x < 255; x++) {
analogWrite(2, x);
delay(5);
}
for (y = 255; y >= 0; y--) {
analogWrite(2, y);
delay(5);
}
break;
case 3:
Blink();
break;
case 4:
item = 0;
break;
}
}
这段代码每次运行到case3就不向下运行了,有时候还会卡在case2那一步,需要长按或者连击才能进行到case3。
页:
[1]