// https://wokwi.com/projects/411181034370782209
//
// From https://wokwi.com/projects/410325174113969153
// by https://wokwi.com/makers/maverick
// per https://discord.com/channels/787627282663211009/1289692132776476853/1289786828915740704
//
uint32_t getKeys() {
uint32_t retval = 0;
for (int i = 2; i < 6; ++i) {
pinMode(i, OUTPUT);
digitalWrite(i, LOW);
for (int j = 6; j < 10; ++j) {
pinMode(j, INPUT_PULLUP);
retval <<= 1;
if (!digitalRead(j)) {
retval |= 0b1;
// Serial.print(j - 5);
// Serial.print(',');
// Serial.print(i - 1);
// Serial.print("P ");
delay(100);
}
}
digitalWrite(i, HIGH);
}
return retval;
}
void setup() {
Serial.begin(115200);
}
void loop() {
static uint32_t last = 0;
uint32_t nowKey = getKeys();
if(nowKey != last){
Serial.print(nowKey,BIN);
Serial.print(':');
Serial.print((nowKey ^ last),BIN);
Serial.println(' ');
last = nowKey;
}
delay(10);
}