Professional Documents
Culture Documents
Nwjsjsbs
Nwjsjsbs
1 #include <Wire.h>;
3 void setup(){
4 Wire.begin();
5 Serial.begin(9600);
6 while (!Serial);
7 Serial.println("\nI2C Scanner");
8 }
10 void loop(){
12 int nDevices;
13 Serial.println("Scanning...");
14
15 nDevices = 0;
17 Wire.beginTransmission(address);
18 error = Wire.endTransmission();
19
20 if (error == 0){
22 if (address<16)
23 Serial.print("0");
24 Serial.print(address,HEX);
25 Serial.println(" !");
26
27 nDevices++;
28 }
29 else if (error==4){
31 if (address<16)
32 Serial.print("0");
33 Serial.println(address,HEX);
34 }
35 }
36 if (nDevices == 0)
38 else
39 Serial.println("selesai\n");
40
41 delay(5000);
42 }