Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "WireScanner.h"
- WireScanner::WireScanner(TwoWire &i2cPort) {
- _i2cPort = &i2cPort;
- }
- void WireScanner::scanI2C(void) {
- byte error, address;
- int nDevices;
- Serial.println("Scanning...");
- nDevices = 0;
- for (address = 1; address < 127; address++) {
- _i2cPort->beginTransmission(address);
- error = _i2cPort->endTransmission();
- if (error == 0) {
- Serial.print("I2C device found at address 0x");
- if (address < 16)
- Serial.print("0");
- Serial.println(address, HEX);
- nDevices++;
- } else if (error == 4) {
- Serial.print("Unknown error at address 0x");
- if (address < 16)
- Serial.print("0");
- Serial.println(address, HEX);
- }
- }
- if (nDevices == 0)
- Serial.println("No I2C devices found");
- else
- Serial.println("done");
- Serial.println((long)&_i2cPort);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement