We have pins defined on Arduino Mega this way:
#define x1 3
#define x2 14
#define x3 22
#define x4 52
#define x5 24
#define x6 50
#define x7 26
#define x8 48
#define x9 28
#define x10 46
#define x11 2
#define x12 15
#define x13 23
#define x14 53
#define x15 25
#define x16 51
#define x17 27
#define x18 49
#define x19 29
#define x20 47
As you can see the pin numbers do not follow a specific order? I do not want to use 20 if statements to read each pin. I am thinking of using arrays, but how do I do it efficiently?
So you have x1-20 in your application, and you have these values hooked up to arbitrary pins on the I/O connector?
Simply define an array mapping between them
PS. You no longer need the #defines anymore, just use
x[N]in place ofxN.