Skip to content

Commit

Permalink
MPR121 sometimes needs a little time to reply to I2C requests, so kee…
Browse files Browse the repository at this point in the history
…p askin'
  • Loading branch information
ladyada committed Dec 27, 2014
1 parent f998062 commit 6f33121
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 2 additions & 3 deletions Adafruit_MPR121.cpp
Expand Up @@ -90,7 +90,6 @@ uint16_t Adafruit_MPR121::baselineData(uint8_t t) {

uint16_t Adafruit_MPR121::touched(void) {
uint16_t t = readRegister16(MPR121_TOUCHSTATUS_L);

return t & 0x0FFF;
}

Expand All @@ -101,15 +100,15 @@ uint8_t Adafruit_MPR121::readRegister8(uint8_t reg) {
Wire.beginTransmission(_i2caddr);
Wire.write(reg);
Wire.endTransmission(false);
Wire.requestFrom(_i2caddr, 1);
while (Wire.requestFrom(_i2caddr, 1) != 1);
return ( Wire.read());
}

uint16_t Adafruit_MPR121::readRegister16(uint8_t reg) {
Wire.beginTransmission(_i2caddr);
Wire.write(reg);
Wire.endTransmission(false);
Wire.requestFrom(_i2caddr, 2);
while (Wire.requestFrom(_i2caddr, 2) != 2);
uint16_t v = Wire.read();
v |= ((uint16_t) Wire.read()) << 8;
return v;
Expand Down
2 changes: 2 additions & 0 deletions examples/MPR121test/MPR121test.ino
Expand Up @@ -27,6 +27,8 @@ uint16_t lasttouched = 0;
uint16_t currtouched = 0;

void setup() {
while (!Serial); // needed to keep leonardo/micro from starting too fast!

Serial.begin(9600);
Serial.println("Adafruit MPR121 Capacitive Touch sensor test");

Expand Down

0 comments on commit 6f33121

Please sign in to comment.