I would propose to store the touch state of the 8 sensors into a single byte (-> "unsigned char"). This saves some RAM (int touch[8] consumes 16 bytes), and improves the performance on logical checks.
To set a flag, use:
touched |= (1 << stribe);
To clear a flag, use:
touched &= ~(1 << stribe);
Check if any sensor is touched:
if( touched ) { ...
Check if no sensor is touched:
if( !touched ) { ...
Check if an individual sensor is touched:
if( touched & (1 << stribe) ) { ...
or
if( touched & and_mask[stribe] ) { ...
where and_mask is globally defined as: "const unsigned char and_mask[8] = { 0xfe, 0xfd, 0xfb, 0xf7, 0xef, 0xdf, 0xbf, 0x7f };"
touched could also be declared as an aggregate (union):
typedef union {
struct {
unsigned ALL:8;
};
struct {
unsigned SENSOR1:1;
unsigned SENSOR2:1;
unsigned SENSOR3:1;
unsigned SENSOR4:1;
unsigned SENSOR5:1;
unsigned SENSOR6:1;
unsigned SENSOR7:1;
unsigned SENSOR8:1;
};
} touched_t;
touched_t touched;
...which not only improves the readability:
if( touched.ALL ) { ...
if( !touched.ALL ) { ...
if( touched.SENSOR1 ) { ...
if( !touched.SENSOR2 ) { ...
but also the performance (again... single flag checks result into a single assembler instruction)
Best Regards, Thorsten.