const uint8_t controlButtonPin = 12; // short press = turn off active LEDs
// Debounce and timing
const unsigned long DEBOUNCE_MS = 40;
const unsigned long CONTROL_SHORTPRESS_MAX_MS = 500;
unsigned long lastDebounceTimeControl = 0;
bool lastControlRaw = false;
bool lastControlStable = false;
unsigned long controlDownTime = 0;
int count = 1;
void setup() {
Serial.begin(9600);
pinMode(controlButtonPin, INPUT_PULLUP);
// put your setup code here, to run once:
}
void loop() {
// put your main code here, to run repeatedly:
bool rawControl = (digitalRead(controlButtonPin) == LOW); // pressed active LOW
unsigned long now = millis();
if (rawControl != lastControlRaw) {
lastDebounceTimeControl = now;
lastControlRaw = rawControl;
}
if ((now - lastDebounceTimeControl) > DEBOUNCE_MS) {
if (rawControl != lastControlStable) {
lastControlStable = rawControl;
if (lastControlStable) {
// button just pressed
controlDownTime = now;
} else {
// button released: check press length
unsigned long len = now - controlDownTime;
Serial.print("Control button was pressed for ");
Serial.println(len);
if (len <= CONTROL_SHORTPRESS_MAX_MS) {
Serial.println("Control Button Short Pressed");
// count += 1;
// count = count % 7;
count = count + 1 > 7 ? 1 : count + 1;
Serial.println(count);
// short press: turn off all PB-activated LEDs (not blue)
// handleDirectionChangeReset();
//lcd.setCursor(0,1);
//lcd.print("Control: SHORT OFF ");
} else if(len > 3000) {
Serial.println("Button pressed for long change state"); // long press (not specified) - ignore or implement later
//lcd.setCursor(0,1);
//lcd.print("Control: LONG press ");
}
}
}
}
}