const int buttonPin = 2; // the number of the pushbutton pin
// variables will change:
int buttonState = 0; // variable for reading the pushbutton status
int counter;
int x=0;
int buttonCount=0;
void setup() {
Serial.begin(115200);
while (!Serial) {
delay(10);
}
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT_PULLUP);
// put your setup code here, to run once:
}
void loop() {
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
// put your main code here, to run repeatedly:
if (buttonState == LOW && buttonCount==0) {
x=counter;
counter = value(x);
buttonCount=1;
delay(200);
}else if(buttonState == HIGH){
buttonCount=0;
}
}
int value(int x){
++x;
Serial.print(x);
if (x>=3){
x=0;
}
return x;
}