Serial Toggle switch help

Ok I have spent hours trying to Get this to work. All I wanna do is use # keys 0-9 as toggle switches. Should work like this... EX: If i press # "1" key LED turns on and stays on. Press # "1" key again LED turns off and stays off. Then rinse and repeat.
I'm a newbie so go easy on me, I'm starting with getting 1 to work first. Whats wrong?

  /*

 serialControl Toggle Switch ver. 1.0
 
 */

// Use pins 5 through 13 as the digital outputs
int output1 = 13;
int output2 = 12;
int output3 = 11;
int output4 = 10;
int output5 = 9;
int output6 = 8;
int output7 = 7;
int output8 = 6;

//int buttonPressTime = 250;   // Number of milliseconds to hold outputs on
//____________________________________________________________________________________

int button1PushCounter = 0;   // counter for the number of button presses
int button1State = 0;         // current state of the button
int lastButton1State = 0;     // previous state of the button

int button2PushCounter = 0;   // counter for the number of button presses
int button2State = 0;         // current state of the button
int lastButton2State = 0;     // previous state of the button


int button3PushCounter = 0;   // counter for the number of button presses
int button3State = 0;         // current state of the button
int lastButton3State = 0;     // previous state of the button

int button4PushCounter = 0;   // counter for the number of button presses
int button4State = 0;         // current state of the button
int lastButton4State = 0;     // previous state of the button

int button5PushCounter = 0;   // counter for the number of button presses
int button5State = 0;         // current state of the button
int lastButton5State = 0;     // previous state of the button

int button6PushCounter = 0;   // counter for the number of button presses
int button6State = 0;         // current state of the button
int lastButton6State = 0;     // previous state of the button

int button7PushCounter = 0;   // counter for the number of button presses
int button7State = 0;         // current state of the button
int lastButton7State = 0;     // previous state of the button

int button8PushCounter = 0;   // counter for the number of button presses
int button8State = 0;         // current state of the button
int lastButton8State = 0;     // previous state of the button



/**
 * Initial configuration
 */
void setup()
{
  // Open the serial connection to listen for commands from the host
  Serial.begin(115200);

  // Set up the pins as outputs
  pinMode(output1, OUTPUT);
  pinMode(output2, OUTPUT);
  pinMode(output3, OUTPUT);
  pinMode(output4, OUTPUT);
  pinMode(output5, OUTPUT);
  pinMode(output6, OUTPUT);
  pinMode(output7, OUTPUT);
  pinMode(output8, OUTPUT);

  // Make sure the outputs are all set LOW initially
  digitalWrite(output1, LOW);
  digitalWrite(output2, LOW);
  digitalWrite(output3, LOW);
  digitalWrite(output4, LOW);
  digitalWrite(output5, LOW);
  digitalWrite(output6, LOW);
  digitalWrite(output7, LOW);
  digitalWrite(output8, LOW);
}

/**
 * Main program loop
 */
void loop() 
{
  byte val;
  val = 0;
  



    // Check if a value has been sent by the host
  if(Serial.available()) {
    val = Serial.read();
    //button1State = (val);


    if (button1State != lastButton1State) { 

      if (button1State == '1') {

        button1PushCounter++;
        
        Serial.print("number of button pushes:  ");
        Serial.println(button1PushCounter, DEC);
      }
      else {

        Serial.println("1 off");
        digitalWrite(output1, LOW);

        lastButton1State = button1State;

        if (button1PushCounter  == 0) {
          digitalWrite(output1, LOW);
        } 
        else {
          digitalWrite(output1, HIGH);
        }
      }
    }
  }
}

I assume you are pressing Enter after pressing the number you want?
I havent looked at your code yet.
The Serial monitor isnt like Hyperterminal where you can just push a number and its instantly transmitted, you have to press Enter to send it (or click send).

Just incase this is your problem.

Had a look at the code.

Good first attempt.

You are reading in the Serial value, and putting in into the variable val, however you then dont do anything with that.
You have a line which assigned button1State with the val, however its commented out.

I have written this quickly for you. It may help.
You shouldnt need to have the last state stored, as really you can check what the value of the current state is before you overwrite it, hence me not using it in my example.
Also I didnt know what you wanted to do with the counter, so I made it count up on every rising edge (every time the state goes to 1) and displays that on the serial port. I havent cleared it however, so you can decide when you want to do that.

I havent tried to compile it or anything, but see if you can get that working.

This is the loop() section of the code only. So just replace your loop() with this as a test.

void loop() 
{
  int val = 0;
  
  // Check if a value has been sent by the host
  if(Serial.available()) 
  {
    val = Serial.read();
    
    switch(val)
    {
      case 1:
      if (button1State == 0)
      {
        button1State = 1;
        digitalWrite(output1, HIGH);
        Serial.println("1 ON");
        button1PushCounter++; 
        Serial.print("Number of button 1 pushes: ");
        Serial.println(button1PushCounter, DEC);    
      }
      else
      {
        button1State = 0;
        digitalWrite(output1, LOW);
        Serial.println("1 OFF");
      }
      
      case 2:
      if (button2State == 0)
      {
        button2State = 1;
        digitalWrite(output2, HIGH);
        Serial.println("2 ON");
        button2PushCounter++; 
        Serial.print("Number of button 2 pushes: ");
        Serial.println(button2PushCounter, DEC);    
      }
      else
      {
        button2State = 0;
        digitalWrite(output2, LOW);
        Serial.println("2 OFF");
      }
    }
  }
}

Hope it is of some help
Keep up the learning, you are doing well.

The code above should work for 1 and 2. Just copy one of the case's, paste and rename for 3 onwards etc.

James