请问这段编程烧录后,LED为何在开关按下时无法关闭?
4接的是按钮,9接的是LED。求大神解答!拜谢!
const int LED = 9;
int i = 0;
const int BUTTON = 4;
boolean state = 0;
int val = 0;
int oldvalue = 0;
void setup() {
pinMode(LED,OUTPUT);
pinMode(BUTTON,INPUT);
}
void loop() {
val = digitalRead(BUTTON);
if( (val == HIGH) && (oldvalue == LOW)){
state = !state;
delay(10);
}
oldvalue = val;
if (state ==1){
for(i=0; i<255; i++){
analogWrite(LED, i);
delay(10);
}
for (i=255; i>0; i--){
analogWrite(LED,i);
delay(10);
}
}else if(state == 0){
analogWrite(LED, 0);
}
}
不懂帮顶 dsweiliang 发表于 2016-3-1 08:41
不懂帮顶
谢谢{:5_197:}{:5_197:}
页:
[1]