
void readTouchInputs(){
if(!checkInterrupt()){
//read
the
touch
state
from
the
MPR121
Wire.requestFrom(0x5A,2);
byte
LSB
= Wire.read();
byte
MSB
= Wire.read();
uint16_t
touched
= ((MSB
<< 8)
| LSB);
//16bits
that
make
up
the
touch
states
for (int i=0;
i
< 12;
i++){
//
Check
what
electrodes
wer
e
pressed
if(touched
& (1<<i)){
if(touchStates[i]
== 0){
//pin
i
was
just
touched
Serial.print("pin
");
Serial.print(i);
Serial.println("
was
just
touched");
}else if(touchStates[i]
== 1){
//pin
i
is
still
being
touched
}
touchStates[i]
= 1;
}else{
if(touchStates[i]
== 1){
Serial.print("pin
");
Serial.print(i);
Serial.println("
is
no
longer
being
touched");
//pin
i
is
no
longer
being
touched
}
touchStates[i]
= 0;
}
}
}
}
The Arduino scans each electrode and prints out a message over serial if
an electrode is triggered as being touched. The Arduino will then print out a
message as soon as the electrode is no longer being touched.
Page 5 of 24