Code adaptation for reading a pressure sensor matrix

@lo9999s, please do not cross-post. Threads merged.

@lo9999s, stop cross-posting. Threads merged.

@lo9999s, STOP CROSS-POSTING.

@lo9999s will be spending a few days away from the forum.

This is an interesting project.

Seeing as you only have a small number of sensors, my approach would be to make a list of the row/column combinations at which a sensor lies and to only do the sensing and transmission if there’s a sensor pad in that spot.

Since there are 16 columns, it would make sense to hold an array of 10 16-bit unsigned quantities and to indicate which combinations have pads at that location using a bit mask.

Optimisations would include skipping an entire row if there were no sensors on the row, and exiting out of the colum loop once there were no more sensors on the row. Come to think of it: those are the same problem.

So, your sensor array would look something like this:

// THIS IS NOT CORRECT - IT"S AN EXAMPLE

t_uint16 pads[ROW_COUNT] = {
  0b0000111100,
  0b0000111110,
  0b0000111110,
  0b0000111110,
  0b0000111100,
  0b0000111100,
  0b0000111000
};

Your loop becomes:

void loop()
{
  compressed_zero_count = 0;
  for(int i = 0; i < ROW_COUNT; i ++)
  {
    setRow(i);
    shiftColumn(true);
    t_uint16 padMask = pads[i];
    for(int j = 0; j < COLUMN_COUNT; j ++)
    {
      if(padMask == 0) break; // no more pads on this row
      if(padMask & 1) { // there's a pad at this position. Perform the read.
        int raw_reading = analogRead(PIN_ADC_INPUT);
        byte send_reading = (byte) (lowByte(raw_reading >> 2));
        sendCompressed(send_reading);
      }
      padMask >>= 1;
      shiftColumn(false);
    }
  }
  if(compressed_zero_count > 0)
  {
    Serial.write((byte) 0);
    Serial.write((byte) compressed_zero_count);
  }
  Serial.write((byte) PACKET_END_BYTE);
}