Use I2CProbe to get address of different brand touches
This commit is contained in:
@@ -13,8 +13,45 @@
|
||||
#include "TouchLib.h"
|
||||
#include "utilities.h"
|
||||
|
||||
TouchLib touch(Wire, BOARD_I2C_SDA, BOARD_I2C_SCL, GT911_SLAVE_ADDRESS1);
|
||||
TouchLib *touch = NULL;
|
||||
uint8_t touchAddress = GT911_SLAVE_ADDRESS2;
|
||||
|
||||
void scanDevices(TwoWire *w)
|
||||
{
|
||||
uint8_t err, addr;
|
||||
int nDevices = 0;
|
||||
uint32_t start = 0;
|
||||
for (addr = 1; addr < 127; addr++) {
|
||||
start = millis();
|
||||
w->beginTransmission(addr); delay(2);
|
||||
err = w->endTransmission();
|
||||
if (err == 0) {
|
||||
nDevices++;
|
||||
Serial.print("I2C device found at address 0x");
|
||||
if (addr < 16) {
|
||||
Serial.print("0");
|
||||
}
|
||||
Serial.print(addr, HEX);
|
||||
Serial.println(" !");
|
||||
|
||||
if (addr == GT911_SLAVE_ADDRESS2) {
|
||||
touchAddress = GT911_SLAVE_ADDRESS2;
|
||||
Serial.println("Find GT911 Drv Slave address: 0x14");
|
||||
} else if (addr == GT911_SLAVE_ADDRESS1) {
|
||||
touchAddress = GT911_SLAVE_ADDRESS1;
|
||||
Serial.println("Find GT911 Drv Slave address: 0x5D");
|
||||
}
|
||||
} else if (err == 4) {
|
||||
Serial.print("Unknow error at address 0x");
|
||||
if (addr < 16) {
|
||||
Serial.print("0");
|
||||
}
|
||||
Serial.println(addr, HEX);
|
||||
}
|
||||
}
|
||||
if (nDevices == 0)
|
||||
Serial.println("No I2C devices found\n");
|
||||
}
|
||||
|
||||
void setup()
|
||||
{
|
||||
@@ -27,7 +64,13 @@ void setup()
|
||||
|
||||
Wire.begin(BOARD_I2C_SDA, BOARD_I2C_SCL);
|
||||
|
||||
touch.init();
|
||||
// Two touch screens, the difference between them is the device address,
|
||||
// use ScanDevices to get the existing I2C address
|
||||
scanDevices(&Wire);
|
||||
|
||||
touch = new TouchLib(Wire, BOARD_I2C_SDA, BOARD_I2C_SCL, touchAddress);
|
||||
|
||||
touch->init();
|
||||
|
||||
}
|
||||
|
||||
@@ -35,9 +78,9 @@ void loop()
|
||||
{
|
||||
// You can judge the level of the touch interrupt to get whether there is a touch
|
||||
if (digitalRead(BOARD_TOUCH_INT)) {
|
||||
bool res = touch.read();
|
||||
bool res = touch->read();
|
||||
if (res) {
|
||||
TP_Point p = touch.getPoint(0);
|
||||
TP_Point p = touch->getPoint(0);
|
||||
Serial.printf("X:%d Y:%d\n", p.x, p.y);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user