Having an issue with my code.

I am new to programming electronics and using them. I wrote this code to light an LED specified, and it compiles and uploads, but never runs.

#define SKIP 0xA
#define MAX_PINS 3
#define NUM_LEDS_STATES 7
#define PIN1 3
#define PIN2 4
#define PIN3 5

int PINS[ MAX_PINS ] = { PIN1 , PIN2 , PIN3 };

int Pin_Mode[ NUM_LEDS_STATES ][ MAX_PINS ] = {// PIN1     PIN3     PIN3
                                               { OUTPUT , OUTPUT , OUTPUT }, // ALL OFF
                                               { INPUT  , OUTPUT , OUTPUT }, // LED 1
                                               { INPUT  , OUTPUT , OUTPUT }, // LED 2
                                               { OUTPUT , OUTPUT , INPUT  }, // LED 3
                                               { OUTPUT , INPUT  , OUTPUT }, // LED 4
                                               { OUTPUT , INPUT  , OUTPUT }, // LED 5
                                               { OUTPUT , OUTPUT , INPUT  }, // LED 6
                                            };
                      
int Pin_State[ NUM_LEDS_STATES ][ MAX_PINS ] = {//PIN1   PIN3   PIN3
                                                { LOW  , LOW  , LOW  }, // ALL OFF
                                                { SKIP , HIGH , LOW  }, // LED 1
                                                { SKIP , LOW  , HIGH }, // LED 2
                                                { LOW  , HIGH , SKIP }, // LED 3
                                                { HIGH , SKIP , LOW  }, // LED 4
                                                { LOW  , SKIP , HIGH }, // LED 5
                                                { HIGH , LOW  , SKIP }, // LED 6
                                              };

void change_led( int led ) {
   for( int loc=0; loc < MAX_PINS; loc++ ) {
     pinMode( PINS[ loc ], Pin_Mode[ led ][ loc ] );

     if( Pin_State[ led ][ loc ] != SKIP ) {
        digitalWrite( PINS[ loc ], Pin_State[ led ][ loc ] );
     }
   }     
}
                       
void setup() { }

void loop() {
  for( int run=1; run < NUM_LEDS_STATES; run++ ) {
     change_led( run );
     delay( 50 ); 
  }
}

If there a better way to write this please let me know.

but never runs.

Go on it does run. Maybe it runs and you don't see any output changing.
I must say it is rather complex, what are you trying to do?

What Mike said and is there any reason this

for( int run=1; run < NUM_LEDS_STATES; run++ ) {

doesn't run from zero?

Remember you probably have the LED on pin 13 to help you debug - maybe lengthen the dealy and slip in some debug prints?

I have 6 LEDs setup with multiplexing. The delay is fine, because I have it changing all the pinmodes all in the loop. setting there doing
pinMode( ledpin1, OUTPUT )
pinMode( ledpin2, OUTPUT)
pinMode(ledpin3,INPUT )
digitalWrite( ledpin1, HIGH )
digitalWrite( ledpin2, LOW )

with each different way to light up each LED, but I wanted away I can just specify what LED to light up without having to do all that, sorta like addressing the location of the LED, what pins need to be in what mode and which are set to HIGH and LOW. So I wrote those array and that function to go through it specifying each LED as a number to each section of array.

I am trying to figure out what application I need on OS X 10.6 so I can open a terminal to the arduino and add in the serial write stuff and see where it hanging up at.

Why would you change the pinMode for a pin with an LED plugged in? Are you expecting that you'll be able to read something from that pin?

Because The pinModes need to be changed for each LED orientation. 2 Needs to be output with HIGH,LOW and the third pin to be an input to for high-impedance.

I don't understand that statement. You can turn an LED on or off, if it is connected to an OUTPUT pin, by writing HIGH or LOW to the pin. You can't obtain any information by reading from a pin that has an LED plugged in, regardless of how you plug the LED in.

Can you clarify?

#Theory Example #
When change_led( 3 ); get executed

it should basically execute

pinMode( 0 , INPUT ); // Causing high-impedance On Pin 3
pinMode( 1, OUTPUT );
digitalWrite( 1, LOW ); //Set Pin 4 Voltage to LOW causing a ground
pinMode( 2, OUTPUT );
digitalWrite( 2, HIGH ); //Set Pin 5 Voltage to High senting 5V through the circuit which will Light only LED # 3

By just executing the code above, it will light LED #3

The LEDs are setup in multiplexing arrangement.

I figured it out.

It wasn't liking this

#define PIN1 3
#define PIN2 4
#define PIN3 5

int PINS[ MAX_PINS ] = { PIN1 , PIN2 , PIN3 };

By changing it to
#define PIN1 3
#define PIN2 4
#define PIN3 5

int PINS[ MAX_PINS ] = { 3,4,5 };

it started working.

?Thanks though.

The comments here don't match the statements. pinMode(0, INPUT) does nothing to pin 3.

You shouldn't need to change the mode of a pin outside of the setup function. A pin is either input or output, unless the thing plugged into it can act as either input or output.

LEDs are output devices.

The digitalWrite command turns output pins on or off. That should be the only command you need to use in the loop method.

Maybe this will make more sense here the schematic I found and built to play with.

I completely understand if you want to implement your own, but here you go: An example that uses a library.

http://www.arduino.cc/playground/Code/Charlieplex

#include <Charlieplex.h>
 
const byte NUMBER_OF_PINS = 3;

//define pins in the order you want to adress them
byte pins[NUMBER_OF_PINS] = {11,12,13};
 
//initialize object
Charlieplex charlieplex = Charlieplex(pins,NUMBER_OF_PINS);
 
//individual 'pins' , adress charlieplex pins as you would adress an array
charliePin led1 = { 1 , 2 }; //led1 is indicated by current flow from 12 to 13
charliePin led2 = { 2 , 1 };
charliePin led3 = { 0 , 2 };
//continue list

void setup(){ /*nothing*/ }
 
void loop(){ 
  plex.charlieWrite(led1,HIGH);
  delay(1000);
  plex.clear();
  plex.charlieWrite(led2,HIGH);
  delay(1000);
  plex.clear();
  plex.charlieWrite(led3,HIGH);
  delay(1000);
  plex.clear();
}

Happy Coding

@PaulS: Google "charlieplexing"

You can't obtain any information by reading from a pin that has an LED plugged in, regardless of how you plug the LED in.

Well, yes you can.
http://www.merl.com/papers/docs/TR2003-35.pdf

FYI I compiled this

int x = PIN1;

void setup ()
{
}

void loop ()
{
}

without errors.

Time to rename those pins ;D

Interesting article, but I don't think that the OP was really interested in reading data from the LED.