Whats the best way to select a set of booleans that will return a state?

So my code has multiple states. Each state has a set of different boolean values. I want to be able to set my code to a particular state and at a later stage be able to return which state its on. So I m trying to pass an input to choose which state to set the code to and then I m trying to return the state. Its kind of like a Karnaugh map.

boolean straight, directionLeft, directionRight;

void setup() 
{
  Serial.begin(115200);
  setDirection(2);
}

void loop() 
{
  int myVal = setDirection();
  Serial.println(myVal);
  delay(5000);
}

int setDirection(int dir)
{
  if(dir == 1)
  {
    straight = true;
    directionLeft = false;
    directionRight = false;
    return 1;
  }
  if(dir == 2)
  {
    straight = false;
    directionLeft = true;
    directionRight = false;
    return 2;
  }
  if(dir == 3)
  {
    straight = false;
    directionLeft = true;
    directionRight = false;
    return 3;
  }
  return 1;
}

So just dealing with passing a parameter to the function and then returning the function without passing a parameter isnt aloud so whats a better way to do this?

A single bit-packed variable seems to fit the bill, to me.

Hi romarshmallow

I want to be able to set my code to a particular state and at a later stage be able to return which state its on.

You could use an enumerated data type:

enum myState {straight, directionLeft, directionRight};
myState currentState = straight;
...
   // example of use
   if ((currentState == straight) && (some other condition))
   {
      currentState = directionLeft;
   }

Regards

Ray

This simple but effective State Machine (SM) library has served me well... SM

Thank you Hackscribble. I was aware of enum but didnt really know how to apply it. So this should work fine for my code. However if you had a set of booleans that consisted of multiple truths and falses rather than a set like the example above where there is only one truth then how would you do that?

Thank you George Matthews, I might check that library out if I have the time.