5390| 2
|
[求助] 请问这段编程烧录后,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); } } |
© 2013-2024 Comsenz Inc. Powered by Discuz! X3.4 Licensed