APDS-9130 library
Diff: Prox.cpp
- Revision:
- 1:159407640167
- Parent:
- 0:10fe9a5a884f
- Child:
- 2:9db88ca586db
--- a/Prox.cpp Mon Jan 04 12:28:26 2016 +0000 +++ b/Prox.cpp Sat Jan 30 20:33:17 2016 +0000 @@ -4,7 +4,7 @@ _sda = sda; _scl = scl; - //WriteByte(0x72,0xE5); // Clear interrupt + WriteByte(0x72,0xE5); // Clear interrupt char PTIME; char WTIME; @@ -19,6 +19,14 @@ WriteByte (0x72, 3, WTIME); WriteByte (0x72, 0xe, PPULSE); + char PIHTL, PIHTH; //Upper interrupt threshold low and high bytes + + PIHTL = 0xFF; + PIHTH = 0x01; //trigger at 256 + + WriteByte (0x72, 0x0A, PIHTL); + WriteByte (0x72, 0x0B, PIHTH); + char PDRIVE; char PDIODE; char PGAIN; @@ -31,26 +39,18 @@ char WEN, PEN, PON, PIEN; WEN = 8; // Enable Wait - PIEN = 5; //Enable interrupt + PIEN = 32; //Enable interrupt PEN = 4; // Enable Prox PON = 1; // Enable Power On WriteByte (0x72, 0, WEN | PIEN | PEN | PON); - char PIHTL, PIHTH; //Upper interrupt threshold low and high bytes - - PIHTL = 0; - PIHTH = 0x80; //trigger at 256 - - WriteByte (0x72, 0x0A, PIHTL); - WriteByte (0x72, 0x0B, PIHTH); - wait(0.12); //Wait for 120 ms } -uint8_t Prox::readProx(){ +uint16_t Prox::readProx(){ WriteByte (0x72, 0xE5); //clear interrupt pin (untested) - uint8_t prox; + uint16_t prox; ReadWord(0x72, 0x18, &prox); return prox; } @@ -61,7 +61,7 @@ // Read a byte on the i2c interface -void Prox::ReadWord(char addr, char reg, uint8_t *data) { +void Prox::ReadWord(char addr, char reg, uint16_t *data) { I2C i2c(_sda,_scl); char reg1 = 0xA0 | reg; char reading[2];