Code problem warning: character constant too long for its type

I am having problem right now with my codes and honestly i am finding it hard to understand why is it acting this way.

Here's my code for reference.

void relayswitch()
{
  SerialState = Serial.read();  
  switch (SerialState)
  {
   case 'OFF' :        digitalWrite(RelaySwitchPin,LOW);
                       digitalWrite(SolenoidPin, LOW);    
                       RelayPinState = 0;                       
                       break;
   case 'ON':          digitalWrite(RelaySwitchPin,HIGH);
                       digitalWrite(SolenoidPin, HIGH);                                              
                       RelayPinState = 1;
                       CoinCounter = 0;
                       Serial.print('\n');               
                       break;   
   case 'LONG':        ShortBondAct();                       
                       break;
   case 'SHORT':       LongBondAct();                       
                       break;  
   default:
                       String Serialstate;
                       Serialstate = &SerialState;  
                       CoinCounter = Serialstate.toInt();
                       break;
  }
}

here are the error messages that i recieved

C:\Users\acer pc\Desktop\Printer_Kiosk_latest\Printer_Kiosk_latest.ino:96:9: warning: character constant too long for its type [enabled by default]

    case 'OFF' :        digitalWrite(RelaySwitchPin,LOW);

         ^

C:\Users\acer pc\Desktop\Printer_Kiosk_latest\Printer_Kiosk_latest.ino:100:9: warning: multi-character character constant [-Wmultichar]

    case 'ON':          digitalWrite(RelaySwitchPin,HIGH);

         ^

C:\Users\acer pc\Desktop\Printer_Kiosk_latest\Printer_Kiosk_latest.ino:106:9: warning: character constant too long for its type [enabled by default]

    case 'LONG':        ShortBondAct();                       

         ^

C:\Users\acer pc\Desktop\Printer_Kiosk_latest\Printer_Kiosk_latest.ino:108:9: warning: character constant too long for its type [enabled by default]

    case 'SHORT':       LongBondAct();                       

         ^

C:\Users\acer pc\Desktop\Printer_Kiosk_latest\Printer_Kiosk_latest.ino: In function 'void relayswitch()':

C:\Users\acer pc\Desktop\Printer_Kiosk_latest\Printer_Kiosk_latest.ino:96:9: warning: case label value exceeds maximum value for type [enabled by default]

    case 'OFF' :        digitalWrite(RelaySwitchPin,LOW);

         ^

C:\Users\acer pc\Desktop\Printer_Kiosk_latest\Printer_Kiosk_latest.ino:100:9: warning: case label value exceeds maximum value for type [enabled by default]

    case 'ON':          digitalWrite(RelaySwitchPin,HIGH);

         ^

C:\Users\acer pc\Desktop\Printer_Kiosk_latest\Printer_Kiosk_latest.ino:106:9: warning: case label value exceeds maximum value for type [enabled by default]

    case 'LONG':        ShortBondAct();                       

         ^

C:\Users\acer pc\Desktop\Printer_Kiosk_latest\Printer_Kiosk_latest.ino:108:9: warning: case label value exceeds maximum value for type [enabled by default]

    case 'SHORT':       LongBondAct();

Any help would be appreciated. Thanks!

Single quotes are for single characters.

You can't directly compare or use switch/case with character strings (character arrays) in C/C++. Use strcmp() for comparisons.

Single quotes denote a single character. OFF is three characters. You can't switch on a string like that. You'll need a series of if statements and use strcmp.

Also, being three characters long you won’t capture OFF with a single Serial.read(). You’ll need three reads to get OFF or 5 reads for SHORT.

There is a Serial Input Basics thread that might be good to read. I don’t have the link but it shouldn’t be hard to search for.

Or use enum:

enum MachineState{
  OFF,
  ON,
  LONG,
  SHORT
};

And transmit just 0,1,2 or 3 respectively

Then use your switch-case:

MachineState myState = Serial.read();
Switch myState
{
  case OFF:
    // do on stuff
    break;
  case ON:
    // do stuff
    break;
  case LONG:
    // do long stuff
    break;
  case SHORT:
    // do short stuff
    break;
}

BulldogLowell: Or use enum:

enum MachineState{
  OFF,
  ON,
  LONG,
  SHORT
};

And transmit just 0,1,2 or 3 respectively

Then use your switch-case:

MachineState myState = Serial.read();
Switch myState
{
  case OFF:
    // do on stuff
    break;
  case ON:
    // do stuff
    break;
  case LONG:
    // do long stuff
    break;
  case SHORT:
    // do short stuff
    break;
}

Just don't forget to make sure it really is 0, 1 or 2, and not '1', '2' or '3'.