In my main loop I continuously poll 10 touch sensors which works as expected in normal circumstances. However when I rapidly touch a couple at the same time for a few seconds the output gets confused, and doesn't regain sync. For example after it has lost sync I will be touching sensor 3, but my out put will be 4,4,4,4,4... then 3, then if I start touching sensor 4, the output will be 3,3,3,3... 4. Its as if the the data is in a queue? or is there a problem with my code below?
//check button states
for (int i = 0; i < nBtn; i++)
{
btnState = digitalRead(buttons[i][0]); //buttons[i] = {pin,state}
if (btnState != buttons[i][1]) //if btn state is different from its recorded state do something
{
if (btnState == 1) //if high send the ID
{
Serial.write(i);
buttons[i][1] = 1; //record new state
}
else
{
buttons[i][1] = 0;
}
}
}