Skip to content

Commit

Permalink
Merge branch 'master' of github.com:adafruit/VCNL4000
Browse files Browse the repository at this point in the history
  • Loading branch information
ladyada committed Apr 17, 2012
2 parents 445f1f4 + 7eca389 commit 9e9e3af
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions vcnl4000.pde
Expand Up @@ -113,15 +113,23 @@ uint8_t read8(uint8_t address)
uint8_t data;

Wire.beginTransmission(VCNL4000_ADDRESS);
#if ARDUINO >= 100
Wire.write(address);
#else
Wire.send(address);
#endif
Wire.endTransmission();

delayMicroseconds(170); // delay required

Wire.requestFrom(VCNL4000_ADDRESS, 1);
while(!Wire.available());

#if ARDUINO >= 100
return Wire.read();
#else
return Wire.receive();
#endif
}


Expand All @@ -131,15 +139,26 @@ uint16_t read16(uint8_t address)
uint16_t data;

Wire.beginTransmission(VCNL4000_ADDRESS);
#if ARDUINO >= 100
Wire.write(address);
#else
Wire.send(address);
#endif
Wire.endTransmission();

Wire.requestFrom(VCNL4000_ADDRESS, 2);
while(!Wire.available());
#if ARDUINO >= 100
data = Wire.read();
data <<= 8;
while(!Wire.available());
data |= Wire.read();
#else
data = Wire.receive();
data <<= 8;
while(!Wire.available());
data |= Wire.receive();
#endif

return data;
}
Expand All @@ -148,7 +167,12 @@ uint16_t read16(uint8_t address)
void write8(uint8_t address, uint8_t data)
{
Wire.beginTransmission(VCNL4000_ADDRESS);
#if ARDUINO >= 100
Wire.write(address);
Wire.write(data);
#else
Wire.send(address);
Wire.send(data);
#endif
Wire.endTransmission();
}

0 comments on commit 9e9e3af

Please sign in to comment.