idir93:
Amazing, but please tell me if there is any easier way to check if button is pressed?
To check if a button is currently pressed:
if (digitalRead(buttonPin))
Serial.println("Button is currently pressed");
To check if a button has just gone from unpressed to pressed:
static boolean lastButtonState = false;
boolean curentButtonState = digitalRead(buttonPin);
if (currentButtonState != lastButtonState) { // State has changes
lastButtonState = currentButtonState;
if (currentButtonState)
Serial.println("Button was just pressed");
else
Serial.println("Button was just released/");