Looping over enum with int values

Hey all,

I am trying to convert a loop function that works now in main code to a library function. And I'm getting a bit confused. The idea is to loop over a group of pins that should be turned on or off (only 1 on at the same moment). I now have:

#define EN_G0 35 // For first pin in group
#define EN_G1 36
#define EN_G2 37
...
#define EN_G5 51

char groupMatrix[6] = {EN_G5, EN_G4, EN_G3, EN_G2, EN_G1, EN_G0}; // This is the order to loop over the pins.

...

/*
 * Function to call in the code to turn a specific group/PIN on. group 0...5
 */
void groupOn(byte group)
{   
    // The channel we will choose
    char pin_EN;
    pin_EN = groupMatrix[group];

    // Set the correct channel open
    digitalWrite(pin_EN, HIGH); 
}

This works fine.

Now: I've read I can make an enum for the groups, and loop over that using the index of the PIN in the enum to turn the PIN on.

Now my confusement: will this work, as EN_Gx is already an int and has a pin ID as the value?

// in the .h file the enumarator
enum groupMatrix_t {EN_G5, EN_G4, EN_G3, EN_G2, EN_G1, EN_G0};

// in .cpp
void groupOn(byte group)
{   
    // The channel we will choose
    //char pin_EN;
    //pin_EN = groupMatrix[group];

    // Set the correct channel open
    //digitalWrite(pin_EN, HIGH);   
    digitalWrite(groupMatrix group, HIGH);
}

Or will I need to use something in the range as given here:

http://stackoverflow.com/questions/10750856/equivalent-to-index-for-enum-type-in-c Answer " If your enum values don't run sequentially from 0 to X in increments of 1, then you can also do the following:

var rank = (rank)Enum.GetValues(typeof(rank))[3]; "

Thanks in advance!

You won't be able to use the C# code shown in that link on the Arduino.

Why do you want to use an enum? An enum is typically used to define a set of values that the user must choose from - such as the days of the week. You don't want the user trying to schedule a task on the 456th day of the week. You want them scheduling a task on Wednesday, for instance.