HELP: Two codes into one

Hi All,
Having some probs with making 2 sketch's work as one!, both work great as separate code.
Here are the codes:

//***ssb audio filter button TEST100***
#include <Wire.h>
#include <LiquidCrystal.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);  // Set the LCD I2C address to 0x27 for a 20 chars and 4 line display

const int switchPin0 = 2;   // set up a constant for the switchPin
int switchState = 0;        // variable to hold the value of the switchPin
int prevSwitchState = 0;    // variable to hold previous value of the switchpin
int buttonPushCounter = 0;  // counter for the number of button presses

void setup() {
  lcd.begin(20, 4);                 // set up the number of columns and rows on the LCD
  pinMode(switchPin0,INPUT);        // set up the switch pin as an input
  digitalWrite(switchPin0, HIGH);   // turn on pullup resistor
  
  //Setup Filter Outputs
  pinMode(A0, OUTPUT);  //Initiates off pin 
  pinMode(A1, OUTPUT);  //Initiates 1.5Khz pin 
  pinMode(A2, OUTPUT);  //Initiates 2.0Khz pin
  pinMode(A3, OUTPUT);  //Initiates 2.5Khz pin
 
}
// pasted new code from here on
void loop()
{
  switchState = digitalRead(switchPin0);   //check the status of the switc
  
  if (switchState != prevSwitchState)      //compare the switchState to its previous state
  {
    if (switchState == LOW)                //If the switch is pressed, count the press
    {
      buttonPushCounter ++;  
      buttonPushCounter %= 4;

    }
    lcd.clear();              //clean up the screen before printin
  }
  // Now, do something with the count
  switch (buttonPushCounter)
  {
  case 0:
    lcd.setCursor(0, 0);
    lcd.print("Off");
    digitalWrite(A0, HIGH);  //Output on
    digitalWrite(A1, LOW);   //Output off
    digitalWrite(A2, LOW);   //Output off
    digitalWrite(A3, LOW);   //Output off
    break;
  case 1:
    lcd.setCursor(0, 0);
    lcd.print("1.5Khz");
    digitalWrite(A0, LOW);   //Output off
    digitalWrite(A1, HIGH);  //Output on
    digitalWrite(A2, LOW);   //Output off
    digitalWrite(A3, LOW);   //Output off
    break;
  case 2:
    lcd.setCursor(0, 0);
    lcd.print("2.0Khz");
    digitalWrite(A0, LOW);  //Output off
    digitalWrite(A1, LOW);  //Output off
    digitalWrite(A2, HIGH);  //Output on
    digitalWrite(A3, LOW);   //Output off
    break;
  case 3:
    lcd.setCursor(0, 0);
    lcd.print("2.5Khz");
    digitalWrite(A0, LOW);   //Output off
    digitalWrite(A1, LOW);   //Output off
    digitalWrite(A2, LOW);   //Output off
    digitalWrite(A3, HIGH);  //Output on
    break;
  }
  prevSwitchState = switchState;  // save the current switch state as the last state
}
//*** RF Att button ***

#include <Wire.h>
#include <LiquidCrystal.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);  // Set the LCD I2C address to 0x27 for a 20 chars and 4 line display

const int switchPin1 = 3;     // set up a constant for the switchPin
int switchState = 0;          // variable to hold the value of the switchPin
int prevSwitchState = 0;      // variable to hold previous value of the switchpin
int buttonPushCounter = 0;   // counter for the number of button presses

void setup() {
  lcd.begin(20, 4);                // set up the number of columns and rows on the LCD
  pinMode(switchPin1,INPUT);       // set up the switch pin as an input
  digitalWrite(switchPin1, HIGH);  // turn on pullup resistor
  
  
   //Setup rf att Outputs
  pinMode(8, OUTPUT);  //Initiates Off pin 
  pinMode(9, OUTPUT);  //Initiates -10dB pin 
  pinMode(10, OUTPUT);  //Initiates -20dB pin
  pinMode(11, OUTPUT);  //Initiates -30dB pin
  pinMode(12, OUTPUT);  //Initiates +10dB pin
}
     
 void loop() 
 {
  switchState = digitalRead(switchPin1);  //check the status of the switch

  if (switchState != prevSwitchState)     //compare the switchState to its previous state
  {   
    if (switchState == LOW)               //If the switch is pressed, count the press
    {
      buttonPushCounter ++;
      buttonPushCounter %= 5;

    } 
    lcd.clear(); //clean up the screen before printin
  }
    switch (buttonPushCounter)
    {
      case 0:
        lcd.setCursor(7, 0);
        lcd.print("off");
        digitalWrite(8, LOW);   //Output off
        digitalWrite(9, LOW);   //Output off
        digitalWrite(10, LOW);   //Output off
        digitalWrite(11, LOW);   //Output off
        digitalWrite(12, LOW);   //Output off
        break;
      case 1:
        lcd.setCursor(7, 0);
        lcd.print("-10dB");
        digitalWrite(8, LOW);   //Output off
        digitalWrite(9, HIGH);  //Output on
        digitalWrite(10, LOW);   //Output off
        digitalWrite(11, LOW);   //Output off
        digitalWrite(12, LOW);   //Output off
        break;
      case 2:
        lcd.setCursor(7, 0);
        lcd.print("-20dB");
        digitalWrite(8, LOW);   //Output off
        digitalWrite(9, LOW);   //Output off
        digitalWrite(10, HIGH);  //Output on
        digitalWrite(11, LOW);   //Output off
        digitalWrite(12, LOW);   //Output off
        break;
      case 3:
        lcd.setCursor(7, 0);
        lcd.print("-30dB");
        digitalWrite(8, LOW);   //Output off
        digitalWrite(9, LOW);   //Output off
        digitalWrite(10, LOW);   //Output off
        digitalWrite(11, HIGH);  //Output on
        digitalWrite(12, LOW);   //Output off
        break;
      case 4:
        lcd.setCursor(7, 0);
        lcd.print("+10dB");
        digitalWrite(8, LOW);   //Output off
        digitalWrite(9, LOW);   //Output off
        digitalWrite(10, LOW);   //Output off
        digitalWrite(11, LOW);  //Output off
        digitalWrite(12, HIGH);   //Output on
        break;
     }
  prevSwitchState = switchState;  // save the current switch state as the last state
}

As i said before they both work as i want, i got my I2C lcd working, had a few probs but sorted now.
What i get confused with is how to get 2 buttons and 2 case to work together.
I need some help please.

Regards
Howard

What i get confused with is how to get 2 buttons and 2 case to work together.
I need some help please.

If I had a tractor and a washing machine, and I asked you to help me get them working together, what would the the first question you'd asked?

"Doing what?" comes to mind. So, I'll ask you the same question. Doing what? What are the requirements for the combined program? What have you tried?

Combining is pretty simple.
Put the stuff before void setup() together,
Put the stuff in void setup() together,
Put the stuff in void loop together.

Get rid of duplicate call outs, like the #includes,
make the other names unique like switchpin0, switchpin1, etc.

//***ssb audio filter button TEST100***
#include <Wire.h>
#include <LiquidCrystal.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);  // Set the LCD I2C address to 0x27 for a 20 chars and 4 line display

const int switchPin0 = 2;   // set up a constant for the switchPin
int switchState = 0;        // variable to hold the value of the switchPin
int prevSwitchState = 0;    // variable to hold previous value of the switchpin
int buttonPushCounter = 0;  // counter for the number of button presses

const int switchPin1 = 3;     // set up a constant for the switchPin
int switchState1 = 0;          // variable to hold the value of the switchPin
int prevSwitchState1 = 0;      // variable to hold previous value of the switchpin
int buttonPushCounter1 = 0;   // counter for the number of button presses

void setup() {
  lcd.begin(20, 4);                 // set up the number of columns and rows on the LCD
  pinMode(switchPin0,INPUT);        // set up the switch pin as an input
  digitalWrite(switchPin0, HIGH);   // turn on pullup resistor

  pinMode(switchPin1,INPUT);       // set up the switch pin as an input
  digitalWrite(switchPin1, HIGH);  // turn on pullup resistor

  //Setup Filter Outputs
  pinMode(A0, OUTPUT);  //Initiates off pin 
  pinMode(A1, OUTPUT);  //Initiates 1.5Khz pin 
  pinMode(A2, OUTPUT);  //Initiates 2.0Khz pin
  pinMode(A3, OUTPUT);  //Initiates 2.5Khz pin

  //Setup rf att Outputs
  pinMode(8, OUTPUT);  //Initiates Off pin 
  pinMode(9, OUTPUT);  //Initiates -10dB pin 
  pinMode(10, OUTPUT);  //Initiates -20dB pin
  pinMode(11, OUTPUT);  //Initiates -30dB pin
  pinMode(12, OUTPUT);  //Initiates +10dB pin

}
// pasted new code from here on
void loop()
{
  switchState = digitalRead(switchPin0);   //check the status of the switc

  if (switchState != prevSwitchState)      //compare the switchState to its previous state
  {
    if (switchState == LOW)                //If the switch is pressed, count the press
    {
      buttonPushCounter ++;  
      buttonPushCounter %= 4;

    }
    lcd.clear();              //clean up the screen before printin
  }
  // Now, do something with the count
  switch (buttonPushCounter)
  {
  case 0:
    lcd.setCursor(0, 0);
    lcd.print("Off");
    digitalWrite(A0, HIGH);  //Output on
    digitalWrite(A1, LOW);   //Output off
    digitalWrite(A2, LOW);   //Output off
    digitalWrite(A3, LOW);   //Output off
    break;
  case 1:
    lcd.setCursor(0, 0);
    lcd.print("1.5Khz");
    digitalWrite(A0, LOW);   //Output off
    digitalWrite(A1, HIGH);  //Output on
    digitalWrite(A2, LOW);   //Output off
    digitalWrite(A3, LOW);   //Output off
    break;
  case 2:
    lcd.setCursor(0, 0);
    lcd.print("2.0Khz");
    digitalWrite(A0, LOW);  //Output off
    digitalWrite(A1, LOW);  //Output off
    digitalWrite(A2, HIGH);  //Output on
    digitalWrite(A3, LOW);   //Output off
    break;
  case 3:
    lcd.setCursor(0, 0);
    lcd.print("2.5Khz");
    digitalWrite(A0, LOW);   //Output off
    digitalWrite(A1, LOW);   //Output off
    digitalWrite(A2, LOW);   //Output off
    digitalWrite(A3, HIGH);  //Output on
    break;
  }
  prevSwitchState = switchState;  // save the current switch state as the last state


    switchState1 = digitalRead(switchPin1);  //check the status of the switch

  if (switchState1 != prevSwitchState1)     //compare the switchState to its previous state
  {   
    if (switchState1 == LOW)               //If the switch is pressed, count the press
    {
      buttonPushCounter1 ++;
      buttonPushCounter1 %= 5;

    } 
    lcd.clear(); //clean up the screen before printin
  }
  switch (buttonPushCounter1)
  {
  case 0:
    lcd.setCursor(7, 0);
    lcd.print("off");
    digitalWrite(8, LOW);   //Output off
    digitalWrite(9, LOW);   //Output off
    digitalWrite(10, LOW);   //Output off
    digitalWrite(11, LOW);   //Output off
    digitalWrite(12, LOW);   //Output off
    break;
  case 1:
    lcd.setCursor(7, 0);
    lcd.print("-10dB");
    digitalWrite(8, LOW);   //Output off
    digitalWrite(9, HIGH);  //Output on
    digitalWrite(10, LOW);   //Output off
    digitalWrite(11, LOW);   //Output off
    digitalWrite(12, LOW);   //Output off
    break;
  case 2:
    lcd.setCursor(7, 0);
    lcd.print("-20dB");
    digitalWrite(8, LOW);   //Output off
    digitalWrite(9, LOW);   //Output off
    digitalWrite(10, HIGH);  //Output on
    digitalWrite(11, LOW);   //Output off
    digitalWrite(12, LOW);   //Output off
    break;
  case 3:
    lcd.setCursor(7, 0);
    lcd.print("-30dB");
    digitalWrite(8, LOW);   //Output off
    digitalWrite(9, LOW);   //Output off
    digitalWrite(10, LOW);   //Output off
    digitalWrite(11, HIGH);  //Output on
    digitalWrite(12, LOW);   //Output off
    break;
  case 4:
    lcd.setCursor(7, 0);
    lcd.print("+10dB");
    digitalWrite(8, LOW);   //Output off
    digitalWrite(9, LOW);   //Output off
    digitalWrite(10, LOW);   //Output off
    digitalWrite(11, LOW);  //Output off
    digitalWrite(12, HIGH);   //Output on
    break;
  }
  prevSwitchState1 = switchState1;  // save the current switch state as the last state
}

I don't have those libraries, but should end up like this.

If you wanted to cycle thru all 8 states, that just needs a little tweaking.

Hi
Thanks for you'r help CrossRoads,

Combining is pretty simple.
Put the stuff before void setup() together,
Put the stuff in void setup() together,
Put the stuff in void loop together.

Get rid of duplicate call outs, like the #includes,
make the other names unique like switchpin0, switchpin1, etc.

I have now managed to combine more switch routines to the code and everything works ok.
The only thing now is that i'am running out of i\o pins, i do have my 20x4 lcd on the i2c.

I have been looking around and seen that i could use a i\o extender or expander board, i need
to add more inputs as well as outputs, would one of these be ok for the job ?.
Would i have to change any code to get the extra i\o's to work ?

Regards
Howard

I don't know what you're connecting up, so maybe on the extender/expander.

Code will have to change - you are pushing the pin decoding into the expansion board, giving up the direct control you have now.
How much IO do you need? 32 total? 54 total?
My 1284 design will do 32.
A Mega will do 54.
Tradeoff the cost of an expansion shield vs a larger Arduino board.
http://www.crossroadsfencing.com/BobuinoRev17/

A board like this will do up to 96 high current sink (pulls low only) outputs (highs need an external pullup resistor), while leaving all but the 4 SPI pins free for inputs.
(designed to sink current thru LED strips from 12V source, strips have built-in current limit resistors)
Inputs are read directly as you do now, outputs are set with SPI.transfer commands, very fast:
digitalWrite(ssPin, LOW);
SPI.transfer(dataByte0);
SPI.transfer(dataByte1);
up to
SPI.transfer(dataByte11);
digitalWrite(ssPin, HIGH);

(and I usually use direct port manipulation instead of digitalWrite to be even faster).