const int dot_pin = 2; const int dash_pin = 3; char last_state = 'X'; void setup() { Serial.begin(115200); pinMode(dot_pin, INPUT_PULLUP); pinMode(dash_pin, INPUT_PULLUP); } void loop() { char current_state = '0'; if (digitalRead(dot_pin) == LOW) { current_state += 1; } if (digitalRead(dash_pin) == LOW) { current_state += 2; } if (current_state != last_state) { Serial.print(current_state); last_state = current_state; } delay(1); // Limit update rate under 1kHz }