獲取lcd i2c地址

include <Wire.h

void
setup
(
)

{

Wire
.begin
(
)
;

Serial
.begin
(
9600
)
;
Serial
.println
(
"\nI2C Scanner"
)
;
}

void
loop
(
)

{

byte
error, address;
int
nDevices;

Serial
.println
(
"Scanning..."
)
;

nDevices = 0
;
for
(
address = 1
; address < 127
; address++ )

{

// The i2c_scanner uses the return value of

// the Write.endTransmisstion to see if

// a device did acknowledge to the address.

Wire
.beginTransmission
(
address)
;
error = Wire
.endTransmission
(
)
;

if
(
error == 0
)

{

Serial
.print
(
"I2C device found at address 0x"
)
;
if
(
address<16
)

Serial
.print
(
"0"
)
;
Serial
.print
(
address,HEX)
;
Serial
.println
(
" !"
)
;

nDevices++;
}

else
if
(
error==4
)

{

Serial
.print
(
"Unknow error at address 0x"
)
;
if
(
address<16
)

Serial
.print
(
"0"
)
;
Serial
.println
(
address,HEX)
;
}

}

if
(
nDevices == 0
)

Serial
.println
(
"No I2C devices found\n"
)
;
else

Serial
.println
(
"done\n"
)
;

delay
(
5000
)
; // wait 5 seconds for next scan

}

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • NAME dnsmasq - A lightweight DHCP and caching DNS server....
    ximitc閱讀 2,993評論 0 0
  • Java經(jīng)典問題算法大全 /*【程序1】 題目:古典問題:有一對兔子,從出生后第3個月起每個月都生一對兔子,小兔子...
    趙宇_阿特奇閱讀 2,077評論 0 2
  • Week 1 Reading a schematic Using a breadboard Resistors...
    Vinchent閱讀 516評論 0 1
  • 昨天在小路自然很奢侈了享受了一天的自然教育培訓(xùn)。在這個培訓(xùn)中,大家就自然教育為了什么做了一點點的討論。 有個面向日...
    WEI_曹蕾閱讀 256評論 4 1
  • 為愛憔悴,為你心碎,為自己流淚。 忘了撕心,忘了裂肺,忘了這一切。 步步停歇,抽抽咽咽,獨自在傷悲。 冷冷一夜,北...
    三古月南閱讀 118評論 0 1

友情鏈接更多精彩內(nèi)容