Combining Switch..case and If statements into a serial control program

I have been working on a program to control a DirecTV STB via an IR blaster as my first Arduino project. I have successfully set up the hardware and multiple sketch’s but need help combining both Switch…case and If statements into one. I need the sketch to allow multiple numerical digit inputs for changing the channel(0-9). Commands are sent via Serial Monitor. I have successfully achieved this using the following sketch:

#include <IRLibAll.h>

IRsend irsender;
byte byteRead;

void(* resetFunc) (void) = 0; 

void setup() {
  Serial.begin(9600);
  Serial.println(" DirecTV  IR Blaster ");
  Serial.println("Input a Command");
}

void loop() {
  if (Serial.available()) {
    byteRead = Serial.read();
    Serial.println(byteRead);

  }
}

void processResponse() {
  switch (byteRead) {      
   case 'o':
      Serial.println("Power");
       irsender.send(DIRECTV,0xc105, 16);
      delay(40);
      Serial.println("Command Sent");
      return;
      break;
    case '0':
      Serial.println("0");
      irsender.send(DIRECTV,0xc116, 16);
      delay(40);
      Serial.println("Command Sent.");
      return;
      break;
    case '1':
      Serial.println("1");
      irsender.send(DIRECTV,0xc011, 16);
      delay(40);
      Serial.println("Command Sent.");
      return;
      break;
    case '2':
      Serial.println("2");
      irsender.send(DIRECTV,0xc022, 16);
      delay(40);
      Serial.println("Command Sent.");
      return;
      break;
    case '3':
      Serial.println("3");
      irsender.send(DIRECTV,0xc033, 16);
      delay(40);
      Serial.println("Command Sent.");
      return;
      break;
    case '4':
      Serial.println("4");
      irsender.send(DIRECTV,0xc043, 16);
      delay(40);
      Serial.println("Command Sent.");
      return;
      break;
    case '5':
      Serial.println("5");
       irsender.send(DIRECTV,0xc054, 16);
      delay(40);
      Serial.println("Command Sent.");
      return;
      break;
    case '6':
      Serial.println("6");
       irsender.send(DIRECTV,0xc065, 16);
      delay(40);
      Serial.println("Command Sent.");
      return;
      break; 
    case '7':
      Serial.println("7");
       irsender.send(DIRECTV,0xc076, 16);
      delay(40);
      Serial.println("Command Sent.");
      return;
      break;
    case '8':
      Serial.println("8");
       irsender.send(DIRECTV,0xc086, 16);
      delay(40);
      Serial.println("Command Sent.");
      return;
      break;
   case '9':
      Serial.println("9");
       irsender.send(DIRECTV,0xc097, 16);
      delay(40);
      Serial.println("Command Sent.");
      return;
      break;
      default: 
      break;
  }
}

However the switch statement does not allow enough cases for all the buttons. The button identifiers begin with DTV to differentiate them from the ones for the TV i will be adding. The following sketch is where the issue lies:

#include <IRLibAll.h>

IRsend irsender;
String input;
byte inputbyte;
char inputchar;
void(* resetFunc) (void) = 0;

void setup() {
  Serial.begin(9600);
    Serial.println("Ready!");
}
void loop() {
  if (Serial.available()) {
    Serial.println("ok");
    input=Serial.readString();
    inputchar=input.charAt(0);
    inputbyte = (byte)inputchar;
    Serial.println(inputbyte);
    numbers();
    power();
  }
}
void numbers() {
switch (inputbyte) { 
    case '0':
      Serial.println("0");
      irsender.send(DIRECTV,0xc011, 16);
      delay(40);
      Serial.println("Command Sent.");
      return;
      break;
    case '1':
      Serial.println("1");
      irsender.send(DIRECTV,0xc011, 16);
      delay(40);
      Serial.println("Command Sent.");
      return;
      break;
    case '2':
      Serial.println("2");
      irsender.send(DIRECTV,0xc022, 16);
      delay(40);
      Serial.println("Command Sent.");
      return;
      break;
    case '3':
      Serial.println("3");
      irsender.send(DIRECTV,0xc033, 16);
      delay(40);
      Serial.println("Command Sent.");
      return;
      break;
    case '4':
      Serial.println("4");
      irsender.send(DIRECTV,0xc043, 16);
      delay(40);
      Serial.println("Command Sent.");
      return;
      break;
    case '5':
      Serial.println("5");
       irsender.send(DIRECTV,0xc054, 16);
      delay(40);
      Serial.println("Command Sent.");
      return;
      break;
    case '6':
      Serial.println("6");
       irsender.send(DIRECTV,0xc065, 16);
      delay(40);
      Serial.println("Command Sent.");
      return;
      break; 
    case '7':
      Serial.println("7");
       irsender.send(DIRECTV,0xc076, 16);
      delay(40);
      Serial.println("Command Sent.");
      return;
      break;
    case '8':
      Serial.println("8");
       irsender.send(DIRECTV,0xc086, 16);
      delay(40);
      Serial.println("Command Sent.");
      return;
      break;
   case '9':
      Serial.println("9");
       irsender.send(DIRECTV,0xc097, 16);
      delay(40);
      Serial.println("Command Sent.");
      return;
      break;
      default: 
      break;
}
}
 void power() {
      if (input == "DTVPOWER") {
      irsender.send(DIRECTV,0xc105, 16);
      delay(40);
      Serial.println("Sent.");
    }
      else {
        CHUP();
      }
  }
  void CHUP(){
    if (input == "DTVCHUP") {
     irsender.send(DIRECTV,0xc0da, 16);
      delay(40);
      Serial.println("Sent.");
    }
      else {
        CHDOWN();
  }
  }
  void CHDOWN() {
    if (input == "DTVCHDOWN") {
      irsender.send(DIRECTV,0xc0eb, 16);
      delay(40);
      Serial.println("Sent.");
    }
      else {
        MENU();
  }
  }
  void MENU() {
    if (input == "DTVMENU") {
      irsender.send(DIRECTV,0xc20a, 16);
      delay(40);
      Serial.println("Sent.");
    }
      else {
        EXIT();
  }
  }
  void EXIT() {
     if (input == "DTVEXIT") {
      irsender.send(DIRECTV,0xc26F, 16);
      delay(40);
      Serial.println("Sent.");
    }
      else {
        GUIDE();
  }
  }
 void GUIDE() {
     if (input == "DTVGUIDE") {
      irsender.send(DIRECTV,0xc280, 16);
      delay(40);
      Serial.println("Sent.");
    }
      else {
        INFO();
  }
  }
  void INFO() {
    if (input == "DTVINFO") {
      irsender.send(DIRECTV,0xc2e5, 16);
      delay(40);
      Serial.println("Sent.");
    }
    else {
      ENTER();
    }
  }
  
  void ENTER() {
     if (input == "DTVENTER") {
      irsender.send(DIRECTV,0xc138, 16);
      delay(40);
      Serial.println("Sent.");
    }
      else {
       PREVIOUS();
  }
  }
   void PREVIOUS() {
     if (input == "DTVPREVIOUS") {
      irsender.send(DIRECTV,0xc0fc, 16);
      delay(40);
      Serial.println("Sent.");
    }
      else {
     delay(40);
      Serial.println("Sent.");
    }
      else {
       DASH();
  }
  }
   void DASH() {
     if (input == "DTVDASH") {
      irsender.send(DIRECTV,0xc127, 16);
      delay(40);
      Serial.println("Sent.");
    }
      else {
       Serial.println("Sorry, Comamnd not found!");
    }
  }

Which works beside not being able to input multiple numerical digits at once as it only accepts the first entered. I feel the issue lies in converting the inputted string into bytes but can not figure out a fix. i know strings are not ideal for this job but am not sure of another easy way to specifically identify with enough combinations. Any guidance would be appreciated! I know the code can also be simplified/improved, in which i will work on once it works. Thank you for your help and patients!

Ok first of all, this:

case '8':
      Serial.println("8");
       irsender.send(DIRECTV,0xc086, 16);
      delay(40);
      Serial.println("Command Sent.");
      return;
      break;

is overkill, return; exits the function after that ‘break;’ is not required.
if you want to be able to read more than 1 digit you should test first to see if there is a digit as a first character to begin with. and then test if the second character maybe a digit. so instead of

input=Serial.readString();
    inputchar=input.charAt(0);
    inputbyte = (byte)inputchar;
    Serial.println(inputbyte);

do something like this

input=Serial.readString();
    inputchar=input.charAt(0);
    if ((inputchar>='0') && (inputchar<='9')) {
      inputbyte = inputchar-'0';
      inputchar=input.charAt(1);
      if ((inputchar>='0') && (inputchar<='9')) {
        inputbyte=inputbyte*10;
        inputbyte=inputbyte+(inputchar-'0');
      }
      Serial.println(inputbyte,DEC);
      numbers();
   }

of course now your ‘inputbyte’ is an actual numerical value ( casting inputbyte = (byte)inputchar; doesn’t actually change much to the value other than removing the sign) so you switch case in numbers() should be like this

void numbers() {
switch (inputbyte) { 
    case 0:
      Serial.println("0");
      irsender.send(DIRECTV,0xc011, 16);
      delay(40);  
      Serial.println("Command Sent.");
      return;

I’m am just trying to clarify your issue and not go into your style of programming (ouch…)
also note that if no numeric value has been found numbers() does not get called.

Deva_Rishi:
Ok first of all, this:

case '8':

Serial.println(“8”);
      irsender.send(DIRECTV,0xc086, 16);
      delay(40);
      Serial.println(“Command Sent.”);
      return;
      break;


is overkill, return; exits the function after that 'break;' is not required. 
if you want to be able to read more than 1 digit you should test first to see if there is a digit as a first character to begin with. and then test if the second character maybe a digit. so instead of 

input=Serial.readString();
    inputchar=input.charAt(0);
    inputbyte = (byte)inputchar;
    Serial.println(inputbyte);


do something like this

input=Serial.readString();
    inputchar=input.charAt(0);
    if ((inputchar>=‘0’) && (inputchar<=‘9’)) {
      inputbyte = inputchar-‘0’;
      inputchar=input.charAt(1);
      if ((inputchar>=‘0’) && (inputchar<=‘9’)) {
        inputbyte=inputbyte*10;
        inputbyte=inputbyte+(inputchar-‘0’);
      }
      Serial.println(inputbyte,DEC);
      numbers();
  }


of course now your 'inputbyte' is an actual numerical value ( casting inputbyte = (byte)inputchar; doesn't actually change much to the value other than removing the sign) so you switch case in numbers() should be like this

void numbers() {
switch (inputbyte) {
    case 0:
      Serial.println(“0”);
      irsender.send(DIRECTV,0xc011, 16);
      delay(40); 
      Serial.println(“Command Sent.”);
      return;


I'm am just trying to clarify your issue and not go into your style of programming (ouch..)
also note that if no numeric value has been found numbers() does not get called.

Yes I know my programming style is well lets say unique. This is much better then when i started, i am slowly getting there. Thank you for your help. I will take a look.

You can reduce your code size quite a bit by using an array instead of duplicating essentially the same code ten times.

const unsigned DTVcodes[10] =  {0xc011, 0xc011, 0xc022,  0xc033, 0xc043, 0xc054, 0xc065,  0xc076,  0xc086, 0xc097};


boolean digit(char c)
{
  if (c >= '0' && c <= '9')
  {
    Serial.println(c);
    irsender.send(DIRECTV, DTVcodes[c - '0'], 16);
    Serial.println("Command Sent.");
    return true;
  }
  return false;
}

This function also returns a value to let you know if the character was a digit. Then you can use it on single digit inputs:

void loop()
{
  if (Serial.available())
  {
    inputchar = Serial.read();


    // First handle line endings: newline or return
    if (inputchar == '\n' || inputchar == '\r')
    {
      // Does the line contain any characters?
      if (input.length() > 0)
      {
        // Yes, so send the appropriate command
        Serial.println("ok");
        power(input)
      }
      input = "";
    }
    else  // Not a line ending.
    {
      // Is it the first character of a line?
      if (input.length() == 0)
      {
        // If it is a digit, send it
        if (!digit(inputchar))
        {
          // It's not a digit, so add it to the input buffer
          input += inputchar;
        }
      }
    }
  }

You can also greatly reduce the length of the command lookup by using another array, this time of structures:

struct Command {const char *command; unsigned code;};


const Command Commands[] =
{
  {"DTVPOWER", 0xc105},
  {"DTVCHUP", 0xc0da},
  {"DTVCHDOWN", 0xc0eb},
  {"DTVMENU", 0xc20a},
  {"DTVEXIT", 0xc26F},
  {"DTVGUIDE", 0xc280},
  {"DTVINFO", 0xc2e5},
  {"DTVENTER", 0xc138},
  {"DTVPREVIOUS", 0xc0fc},
  {"DTVDASH", 0xc127}
};


const size_t CommandCount = sizeof Commands / sizeof Commands[0];


void command(String command)
{
  for (size_t i = 0; i < CommandCount; i++)
  {
    if (command == Commands[i].command)
    {
      irsender.send(DIRECTV, Commands[i].code, 16);
      Serial.print(command);
      Serial.println(" sent.");
      return;
    }
  }
  
  Serial.print("Sorry, Command ");
  Serial.print(command);
  Serial.println(" not found!");
}