Flight Simulator Control Panel - Leonardo with more inputs!

Okay folks, I'm throwing myself on the mercy of the community. I am an UTTER newb when it comes to programming, and am doing my best to learn as I go.

I'm building a control panel for a simulator. Simple stuff, just need to hook up a small pile of buttons to a computer, where each one sends a keyboard press when used. Here's the basic code I've been working with:

const int potPin0 = 0;
const int potPin1 = 1;
const int momentaryPin1 = 2;
const int momentaryPin2 = 3;
const int momentaryPin3 = 4;
const int momentaryPin4 = 5;
const int momentaryPin5 = 6;
const int momentaryPin6 = 7;
const int momentaryPin7 = 8;
const int momentaryPin8 = 9;
const int momentaryPin9 = 10;
const int momentaryPin10 = 11;
const int momentaryPin11 = 12;
const int momentaryPin12 = 13;
int val = 0; 

void setup() {
  pinMode(momentaryPin1, INPUT_PULLUP);
  pinMode(momentaryPin2, INPUT_PULLUP);
  pinMode(momentaryPin3, INPUT_PULLUP);
  pinMode(momentaryPin4, INPUT_PULLUP);
  pinMode(momentaryPin5, INPUT_PULLUP);
  pinMode(momentaryPin6, INPUT_PULLUP);
  pinMode(momentaryPin7, INPUT_PULLUP);
  pinMode(momentaryPin8, INPUT_PULLUP);
  pinMode(momentaryPin9, INPUT_PULLUP);
  pinMode(momentaryPin10, INPUT_PULLUP);
  pinMode(momentaryPin11, INPUT_PULLUP);
  pinMode(momentaryPin12, INPUT_PULLUP);
  Keyboard.begin();
}


void loop() {
  //momentary switch reading
  int buttonState1 = digitalRead(momentaryPin1);
  if (buttonState1 == LOW) {
    Keyboard.print("button 1");
    delay(500);
  }
  
  //momentary switch reading
  int buttonState2 = digitalRead(momentaryPin2);
  if (buttonState2 == LOW) {
    Keyboard.print("button 2");
    delay(500);
  }
  
  //momentary switch reading
  int buttonState3 = digitalRead(momentaryPin3);
  if (buttonState3 == LOW) {
    Keyboard.print("button 3");
    delay(500);
  }
  
  //momentary switch reading
  int buttonState4 = digitalRead(momentaryPin4);
  if (buttonState4 == LOW) {
    Keyboard.print("button 4");
    delay(500);
  }
  
  //momentary switch reading
  int buttonState5 = digitalRead(momentaryPin5);
  if (buttonState5 == LOW) {
    Keyboard.print("button 5");
    delay(500);
  }
  
  //momentary switch reading
  int buttonState6 = digitalRead(momentaryPin6);
  if (buttonState6 == LOW) {
    Keyboard.print("button 6");
    delay(500);
  }
  
  //momentary switch reading
  int buttonState7 = digitalRead(momentaryPin7);
  if (buttonState7 == LOW) {
    Keyboard.print("button 7");
    delay(500);
  }
  
  //momentary switch reading
  int buttonState8 = digitalRead(momentaryPin8);
  if (buttonState8 == LOW) {
    Keyboard.print("button 8");
    delay(500);
  }
  
  //momentary switch reading
  int buttonState9 = digitalRead(momentaryPin9);
  if (buttonState9 == LOW) {
    Keyboard.print("button 9");
    delay(500);
  }
  
  //momentary switch reading
  int buttonState10 = digitalRead(momentaryPin10);
  if (buttonState10 == LOW) {
    Keyboard.print("button 10");
    delay(500);
  }
  
  //momentary switch reading
  int buttonState11 = digitalRead(momentaryPin11);
  if (buttonState11 == LOW) {
    Keyboard.print("button 12");
    delay(500);
  }
  
  //momentary switch reading
  int buttonState12 = digitalRead(momentaryPin12);
  if (buttonState12 == LOW) {
    Keyboard.print("button 13");
    delay(500);
  }
  
  
  
  //pot reading
  static int oldPotState0 = analogRead(potPin0);
  val = analogRead(potPin0);
  
  if (val > (oldPotState0 + 50) || val < (oldPotState0 - 50)) {    
    if (val < (oldPotState0 - 50)) {
        Keyboard.println("pot1 -");
    } else if (val > (oldPotState0 + 50)) {
        Keyboard.println("pot1 +");
    }
    
    oldPotState0 = val;
  }
  //pot reading 2
  static int oldPotState1 = analogRead(potPin1);
  val = analogRead(potPin1);
  
  if (val > (oldPotState1 + 50) || val < (oldPotState1 - 50)) {    
    if (val < (oldPotState1 - 50)) {
        Keyboard.println("pot2 -");
    } else if (val > (oldPotState1 + 50)) {
        Keyboard.println("pot2 +");
    }
    
    oldPotState1 = val;
  }
  
  
  
  
}

Initially, the plan was to have about a dozen buttons and a few potentiometers or so, but it's grown. To the point where I've now exceeded my pins. So I assumed using a shift register would do the job. So ordered up a couple of 74HC165 breakout boards from Sparkfun… and have hit an absolute brick wall in modifying the code. I've looked at the Arduino playground example until my eyes glazed over, but just don't seem to be getting it. I realize that most of you are reading this and thinking that I'm an absolute moron, that there's nothing easier, and the examples are crystal - and am sure they are. But… my head's just not wrapping around it.

So if anyone with a minute to spare could help me out, I'd massively appreciate it! :blush:

What is the problem exactly?
Code doest not work? --Post errors
or need more inputs? -- you can use analog inputs as digitals, try a bigger board, use multiplexors.

Lets us know as to help you.

You need to do a better job of describing the design criteria. "A bunch of pots and buttons" is not going to cut it.
You need to list each and every button , pot or led in a BOM with a description of the function. Your code with all the numbered buttons and pots doesn't tell us anything. You need to decide what you're going to do and how you're going to do it.
We can help with how to do it but only if you know what it is you're trying to do. That is still not clear.

Sorry lads, will try to be more clear.

Originally, I was putting together what is essentially a keyboard using the Leonardo. An array of a dozen buttons, so when you hit one, it sends a corresponding keystroke. I was going to use potentiometers for a couple of the commands (for example, radar range is increased by repeatedly pressing +, or decreased by pressing -) The code I was using is in the original post, and it works fine.

Unfortunately, as I sat down to put it together, I realized I needed more than a dozen. I need 24 digital inputs and 3 analog. Obviously, this is more than the Leonardo can provide, so I ordered 3x 74HC165 breakout boards from Sparkfun that can be daisy chained, and require three pins on the Leonardo to control (SCK, MISO, and one of the digital pins, via SPI) that should be here later in the week. (So don't have them on hand to play with them yet, but they seem extremely straightforward in terms of wiring). But if I can add two shift registers to the Leonardo, then I lose three digital pins, but gain 16. Which means plenty of buttons, and can add an LCD as well, if needed.

I've been scouring the web for tutorials on adding the 74HC165, and the one I've been focusing on is Nick Gammon's here: Gammon Forum : Electronics : Microprocessors : Using a 74HC165 input shift register

The problem I'm having is wrapping my head on reading the button press from the shift register, and translating that to a keyboard.write. Which I'm sure for many of you is idiotic, and something I should know. But just started with Arduinos a fortnight ago, and am fumbling in the dark for the most part.

Why don't you download the 74HC165 Example code from the same psge where you ordered them? (down at the bottom of the page)

Maybe you should read this:
http://forum.arduino.cc/index.php?topic=238025.new;topicseen#new

You need to start with an Adruino, your shift reg and its 8 buttons. Then write code to just read the shift reg and out put the result on Serial. Drop all the rest keep it as simple as you can. Post the code and the circuit diagram if you still have problems.

By the way providing that only one button can be pressed at a time then you can have 4 or 8 inputs to a single analog pin. Look in the playground for other way to expand the number of inputs or go to a Arduino mega (simples!)

Mark

Why don't you download the 74HC165 Example code from the same psge where you ordered them? (down at the bottom of the page)