Another Arduino Keyboard (Control Panel) Question...

Heya folks - before I start, feel free to point, laugh, and yell at me. I'm a total moron when it comes to this, but thought I'd throw myself on your mercy anyways!

So my electrical experience is quite minimal, but I've been able to put together a MAME cabinet using a basic keyboard controller (i-pac). I want to do something similar for a space sim that's coming out (Elite Dangerous) where I build a control panel to use instead of the keyboard to handle the basic "ship" functions.

Now if I was just using momentary switches to replicate the keys, then I could just use another i-pac. Easy! But the panel won't be just buttons, it'll be a combination of buttons and toggle switches. Obviously, with a toggle switch connected to a standard keyboard controller, it'll just infinitely repeat the corresponding letter when the switch is thrown open, rather than just send the keypress once. So was wondering about doing this with an Arduino? I've got an Uno lying around that I've learned can be reflashed to act as a HID or gamepad, but have also read that any time I want to change it or make any updates, it needs to be reflashed to default, the new sketch uploaded, then reflashed again? (So seems a Leonardo would be a better bet?)

Any advice or direction is appreciated. And again, apologies for asking what I'm going to assume is a stupid question.

ubermick:
So seems a Leonardo would be a better bet?

You are right - a Leonardo (Pro Micro) would be a better bet to construct a HID, but even then there is a caveat in regard to uploading new sketches.

Cheers for that Paul.

From continued sniffing, I've found tutorials on how to create a sketch to take care of using momentary switches as keyboard inputs. What I'm having trouble finding is a way of using toggle switches to send a single "letter" rather than acting as if the key is permanently held down. I found some info on a flight sim forum that said it can be done by using relays for each switch (using a keyboard hack, as opposed to an Arduino) but that's going to be rather messy - and was wondering if there's a way to do that via programming?

ubermick:
and was wondering if there's a way to do that via programming?

Well, of course there is - there must always be - and in fact, it is part of the "debounce" code that you must have, anyway.

So the rule is - post the code that you are trying to start with, and we will see what we can do.

Actually, I… got it working! Managed to get the Leonardo playing nice with a toggle switch, potentiometer, as well as a standard pushbutton:

const int switchPin = 2;
const int momentaryPin = 3;
const int potPin = 0;

int val = 0; 

void setup() {
  pinMode(switchPin, INPUT_PULLUP);
  pinMode(momentaryPin, INPUT_PULLUP);
  Keyboard.begin();
}


void loop() {
  
  //toggle switch reading
  static boolean oldSwitchState = digitalRead(switchPin);
  boolean newSwitchState = digitalRead(switchPin);
  if (newSwitchState != oldSwitchState) {
    oldSwitchState = newSwitchState;
    Keyboard.println("S");
  }
 
  //momentary switch reading
  int buttonState = digitalRead(momentaryPin);
  if (buttonState == LOW) {
    Keyboard.print("M");
    delay(250);
  }
  
  //pot reading
  static int oldPotState = analogRead(potPin);
  val = analogRead(potPin);
  
  if (val > (oldPotState + 50) || val < (oldPotState - 50)) {    
    if (val < (oldPotState - 50)) {
        Keyboard.println("-");
    } else if (val > (oldPotState + 50)) {
        Keyboard.println("+");
    }   
    oldPotState = val;
  }
}