const int ledPin = 13;
const int buttonpin = 2;
int buttonstate = 0;
bool state = false;
void setup() {
Serial.begin(115200);
pinMode(ledPin,OUTPUT);
pinMode(buttonpin, INPUT);
// put your setup code here, to run once:
}
void loop() {
buttonstate = digitalRead(buttonpin);
Serial.println(buttonstate);
if (buttonstate == HIGH) {
state = true;
while (state) {
buttonstate = digitalRead(buttonpin);
digitalWrite(ledPin,HIGH);
if (buttonstate == HIGH) {
state = false;
buttonstate == LOW;
}
}
} else {
digitalWrite(ledPin,LOW);
}
// put your main code here, to run repeatedly:
}