int i;
void setup() {
//start serial connection
Serial.begin(9600);
//configure pin2 as an input and enable the internal pull-up resistor
pinMode(2, INPUT_PULLUP);
pinMode(13, OUTPUT);
}
int down=0;
boolean light=false;
void loop() {
if(digitalRead(2)==LOW){i=2;}
checkbutton();
}
void checkbutton(){
if(digitalRead(i)==LOW && down==0){
down=1;
light = !light;
}
if(digitalRead(i)==HIGH && down==1){
down=0;
}
digitalWrite(i+20, light);
}
沒有留言:
張貼留言