<br><img><br><img><br><img><br>LZ,仔细一看电路还真有问题,IO 你用的3和4,不是4和5啊,按键电路一般要加上上拉电阻,用4.7kΩ,点亮按键没有按下时IO口是高电平,当按下点亮按键时IO口是低电平,这时单片机读回来的电平是低电平,点亮LED;熄灭按键也是一样,要用上拉电阻才可靠。回去我画个图和程序给你。<br><img><br><img><br>该用户从未签到<br><img><br>电路没问题,程序没有进行抖动处理,LZ应该很少写程序<br>小白一个。。。。入门都没入,大神指点一下,可以吧<br><img><br><img><br><img><br>求,大神<br>// Handle the Button 抖动<br>// bytsaiwn@ydu.edu.tw 育达科大 多媒体与游戏系; 苗栗; 台湾<br>int btA = 3; // 5 ? 压下开灯 pin 3 ? pin 5 ? change it by yourself; 0.168 second should be enough<br>int btB = 4; // 压下熄灭灯<br>int led = 13;<br>int bounce = 168; // bounce time for 抖动判断; you can change it to test it<br>void setup( ) {<br>pinMode (btA,INPUT_PULLUP);<br>pinMode (btB,INPUT_PULLUP);<br>pinMode (led,OUTPUT);<br>}<br>int aStat = HIGH; //没按下是 HIGH (因INPUT_PULLUP)<br>int bStat = HIGH;<br>void loop( ) {<br>if( clickA( ) ) digitalWrite(led,HIGH);<br>if( clickB( ) ) digitalWrite(led, LOW);<br>} // loop(<br>long lastHitAA = 0;<br>long lastHitBB = 0;<br>bool clickCheck(int btn, int& status, long& lastTime); // declare<br>bool clickA( ) {<br>return clickCheck(btA, aStat, lastHitAA);<br>}<br>bool clickB( ) {<br>return clickCheck(btB, bStat, lastHitBB);<br>}<br>bool clickCheck(int bt, int& xxStat, long& lastHit) {<br>int a = digitalRead(bt);<br>if(a == xxStat) return false; // no change<br>long m = millis( );<br>if(a == LOW) { // 压下 !<br>if(m - lastHit<br></table>