user67229: Hello Arduino Stack Exchange,
I have an an enum instance called state:
enum States
{
  SLEEP,
  AWAKE,
  CRAZY
} state;
States state = SLEEP;

I would like to convert the value of state to a String so I can serially print it using Serial.println().
Currently, when I type String(state), I get a value 0, 1, etc.  I suppose this corresponds with the index of the enum's key.
How can I get it to return "SLEEP", "AWAKE", etc.?

user37622: You can print the value as it is:
Serial.println(state);

This will print the the ordering number of the enum, but you can specify the value as any number or char.
enum States
{
  SLEEP = 'S',
  AWAKE = 'A',
  CRAZY = 'C'
};

Now if you print it with cast to char Serial.println((char) state); it will print a character, which in my opinion is much better then some number.
If you want to convert the enum values identifiers to strings you can do it with a preprocessor macro.
enum States
{
  SLEEP,
  AWAKE,
  CRAZY
} state;

#define IDNAME(name) #name
const char* stateNames[] = {IDNAME(SLEEP), IDNAME(AWAKE), IDNAME(CRAZY)};

I don't think this is better then to print the char values. To do a pretty print it is better to use descriptions.
const char* stateStr[] = {"Sleep", "Awake", "Undefined"};
Serial.println(stateStr[state]);


67229: <p>Hello Arduino Stack Exchange,</p>
<p>I have an an <code>enum</code> instance called <code>state</code>:</p>
<pre class="lang-C prettyprint-override"><code>enum States
{
  SLEEP,
  AWAKE,
  CRAZY
} state;
States state = SLEEP;
</code></pre>
<p>I would like to convert the value of <code>state</code> to a <code>String</code> so I can serially print it using <code>Serial.println()</code>.</p>
<p>Currently, when I type <code>String(state)</code>, I get a value <code>0</code>, <code>1</code>, etc.  I suppose this corresponds with the index of the <code>enum</code>'s key.</p>
<p>How can I get it to return <code>&quot;SLEEP&quot;</code>, <code>&quot;AWAKE&quot;</code>, etc.?</p>
 37622: <p>You can print the value as it is:</p>
<pre><code>Serial.println(state);
</code></pre>
<p>This will print the the ordering number of the enum, but you can specify the value as any number <strong>or char</strong>.</p>
<pre><code>enum States
{
  SLEEP = 'S',
  AWAKE = 'A',
  CRAZY = 'C'
};
</code></pre>
<p>Now if you print it with cast to char <code>Serial.println((char) state);</code> it will print a character, which in my opinion is much better then some number.</p>
<p>If you want to convert the enum values identifiers to strings you can do it with a preprocessor macro.</p>
<pre><code>enum States
{
  SLEEP,
  AWAKE,
  CRAZY
} state;

#define IDNAME(name) #name
const char* stateNames[] = {IDNAME(SLEEP), IDNAME(AWAKE), IDNAME(CRAZY)};
</code></pre>
<p>I don't think this is better then to print the char values. To do a pretty print it is better to use descriptions.</p>
<pre><code>const char* stateStr[] = {&quot;Sleep&quot;, &quot;Awake&quot;, &quot;Undefined&quot;};
Serial.println(stateStr[state]);
</code></pre>
