- void setup()
- {
- for(int i=0,j=9;i<=8,j<=13;i++,j++) //设置0-8为输入,9-13为输出
- {pinMode(i,INPUT);pinMode(j,OUTPUT);}
- }
- void loop() {
- if(digitalRead(1) == HIGH) //有按键按下
- {
- delay(20); //延时去抖动
- if(digitalRead(1) == HIGH) //有按键按下
- {
- digitalWrite(9,!digitalRead(9)); //LED的状态翻转
- while(digitalRead(1) == HIGH); //等待按键松手
- }
- }
- if(digitalRead(2) == HIGH) //有按键按下
- {
- delay(20); //延时去抖动
- if(digitalRead(2) == HIGH) //有按键按下
- {
- digitalWrite(9,!digitalRead(9)); //LED的状态翻转
- while(digitalRead(2) == HIGH); //等待按键松手
- }
- }
- }
复制代码
|