Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: main.cpp
- Revision:
- 0:f4dce843ac31
- Child:
- 1:6282a1ee1391
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Thu Dec 15 09:37:19 2016 +0000
@@ -0,0 +1,40 @@
+// Original program found here: http://playground.arduino.cc/Main/I2cScanner
+// Modified by Domen Ornik, 4.5.2015
+
+#include "mbed.h"
+
+I2C i2c(I2C_SDA , I2C_SCL );
+
+int main() {
+ printf("\nI2C Scanner");
+
+ while(1) {
+ int error, address;
+ int nDevices;
+
+ printf("Scanning...\n");
+
+ nDevices = 0;
+
+ for(address = 1; address < 127; address++ )
+ {
+ i2c.start();
+ error = i2c.write(address << 1); //We shift it left because mbed takes in 8 bit addreses
+ i2c.stop();
+ if (error == 1)
+ {
+ printf("I2C device found at address 0x%X", address); //Returns 7-bit addres
+ nDevices++;
+ }
+
+ }
+ if (nDevices == 0)
+ printf("No I2C devices found\n");
+ else
+ printf("\ndone\n");
+
+ wait(5); // wait 5 seconds for next scan
+
+ }
+ }
+
\ No newline at end of file