I am replacing an antique 10 pin dot matrix printer with an arduino. The following code does not work as expected:
// #INCLUDES
/* none */
#define PINCOUNT 10
#define PIN1 22
#define PIN2 24
#define PIN3 26
#define PIN4 28
#define PIN5 30
#define PIN6 32
#define PIN7 34
#define PIN8 36
#define PIN9 38
#define PIN10 40
#define STROBEP 25
#define STROBER 27
#define PRINTSTART 29
int pins[] = { PIN1, PIN2, PIN3, PIN4, PIN5, PIN6, PIN7, PIN8, PIN9, PIN10 };
void setup( void ) {
pinMode( MOTORSENSE, INPUT ); //raised by board when its time to print
pinMode( STROBEP, OUTPUT ); //set low to trigger
pinMode( STROBER, OUTPUT );
Serial.begin( 9600 );
for( int c = 0; c < PINCOUNT; c++ ) {
pinMode( pins[c], INPUT_PULLUP );
//for debugging only:
Serial.println( pins[c] );
//end debugging
}
}
void loop( void ){ ; }
This code prints:
1 //I expected 22 as per '#define PIN1 22' and 'pins={PIN1 ... PIN10}'
2
3
4
5
6
36 //these last 3 are correct.
38
40
Suspecting that maybe PIN1 (etc) was defined elsewhere, I renamed all the #defines as LPRPIN1 (etc), which yielded the same problem again. It took me a while (and several beers) to figure out that if I #defined the pins as '#define FOO1 22' (etc) instead it worked as expected.
On further reflection, I know now that it was silly to try and define things like PIN1 in an environment designed for a board that it covered with PINs of its own, but I really don't understand this behaviour, especially since I have not included anything that may overwrite my defines.
Even though I have solved the immediate issue, I still don't understand the problem. Can anyone shed some light on whats happening here?
This is Arduino 1.0.6 on an Mega 2560
Thank you