eopett
4
#include <ezButton.h>
const int RUN = 4;
const int ResetTest = 3;
const int PassLED = 12;
const int FailLed = 11;
const int RelayDrive = 8;
const int SHORT_PRESS_TIME = 7999; // 1000 milliseconds
const int LONG_PRESS_TIME = 1201; // 1000 milliseconds
int input = Serial.parseInt(); // keep other operations outside the constrain function
int constrainedInput = constrain(input, 8000, 12000);
ezButton button(2); // create ezButton object that attach to pin 2;
unsigned long pressedTime = 0;
unsigned long releasedTime = 0;
bool isPressing = false;
bool isLongDetected = false;
const int PassLed = 12;
const int FailLed = 11;
void setup() {
Serial.begin(9600);
button.setDebounceTime(50); // set debounce time to 50 milliseconds
}
void loop() {
button.loop(); // MUST call the loop() function first
if (button.isPressed()) {
pressedTime = millis();
isPressing = true;
isLongDetected = false;
}
if (button.isReleased()) {
isPressing = false;
releasedTime = millis();
long pressDuration = releasedTime - pressedTime;
if ( pressDuration < SHORT_PRESS_TIME )
Serial.println("A short press is detected");
}
if (isPressing == true && isLongDetected == false) {
long pressDuration = millis() - pressedTime;
if ( pressDuration > LONG_PRESS_TIME ) {
Serial.println("A long press is detected");
isLongDetected = true;
}
if ( pressDuration = constrainedInput ) {
Serial.println("Pass");
isLongDetected = true;
}
}
}