/*
https://forum.arduino.cc/t/difference-of-2-positions/1403869/
2025-08-25 prototype by noiasca
*/
#include <Streaming.h>
const uint8_t inPin[] {A0, A1, A2, A3}; // the pins for the nails
const size_t noOfPin = sizeof(inPin) / sizeof(inPin[0]); // how many nails/buttons
const uint8_t order[noOfPin] {0, 1, 2, 3}; // the order of how the nails/buttons must be pressed
uint8_t current = 0; // current position to check
void restart() {
current = 0;
Serial << F("restart") << endl;
}
void gameplay() {
for (size_t i = 0; i < noOfPin; i++) { // loop through each button
if (digitalRead(inPin[i]) == LOW) { // check if button is pressed/nailed
if (order[current] == i ) { // check if in correct order
Serial << i << F(" is correct") << endl;
current++;
if (current == noOfPin) { // check if end is reached
Serial << F("perfect match - end of game") << endl;
restart();
}
}
else {
Serial << i << F(" is wrong - end of game") << endl;
restart();
}
delay(500); // dirty delay for a simple debounce
}
}
}
void setup() {
Serial.begin(115200);
Serial << F("setup") << endl;
for (size_t i = 0; i < noOfPin; i++) pinMode(inPin[i], INPUT_PULLUP);
}
void loop() {
gameplay();
}
//