blob: 5588f5c74d400f4790f40b68008cacc9f055e7ed (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
#pragma once
#include <Arduino.h>
#include <Wire.h>
#include "log.h"
namespace ocularium {
inline void scan(TwoWire& wire, bool post_delay = true)
{
for(auto address = 1; address < 127; address++)
{
wire.beginTransmission(address);
const uint8_t error = wire.endTransmission();
if (error == 0)
{
LOGGER.print("I2C device found at address 0x");
if (address<16)
LOGGER.print("0");
LOGGER.print(address,HEX);
LOGGER.println();
}
else if (error==4)
{
LOGGER.print("Unknown error at address 0x");
if (address<16)
LOGGER.print("0");
LOGGER.println(address,HEX);
}
}
if (post_delay)
{
// Let the bus settle before doing anything else.
delay(10);
}
}
}
|