Arduino初学必会程序2
3.按键开关(类似家庭开关) 要电路图的联系我,晚上尽量给你#define LED 13#define KEY 2int K=0;void setup() {pinMode(LED,OUTPUT);pinMode(KEY,INPUT_PULLUP); //使能上拉功能}void loop() { Anjian();if(K==1) { digitalWrite(LED,!digitalRead(LED)); //状态位取反,使这灯处于高电平或低 电平 }}void Anjian() //按键扫描程序,判断高低电平{K=0; if(digitalRead(KEY)==LOW) {delay(20); //消除抖动 if(digitalRead(KEY)==LOW) {K=1; while(digitalRead(KEY)==LOW); }}}
页:
[1]