const unsigned char combo[] = {0, 1, 2, 3, 4,};
void setup() {
Serial.begin(115200); // hello, it's 2022
Serial.println("Hello Combination World!\n");
DDRD &= ~0xf8;
PORTD |= 0xf8;
}
void loop() {
static unsigned long lastTime;
static unsigned char lastEntry;
static unsigned char next;
unsigned long now = millis();
if (now - lastTime < 20) return; // throttled loop. get over it.
lastTime = now;
unsigned char entry = (PIND ^ 0xff) >> 3;
unsigned char delta = entry & ~lastEntry;
lastEntry = entry;
if (!delta)
return;
if (delta == (1 << combo[next])) next++;
else {
Serial.println("Bzzzt!");
next = 0;
}
if (next == 5) {
Serial.println("OKAY!");
next = 0;
}
}