Henrique Rosa / Mbed 2 deprecated adress_I2C

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 
00003 I2C i2c(I2C_SDA, I2C_SCL); 
00004 
00005 int main(){
00006     printf("\nI2C Scanner running...\n");
00007     //i2c.frequency(400000);
00008     int error, address, nDevices;
00009     nDevices = 0;
00010     for(address = 0; address < 128; address++ ){
00011         thread_sleep_for(10);
00012         error = i2c.write(address  << 1, "1", 1);
00013 
00014         if (error == 0){
00015             printf("I2C device found at address 8bit: 0x%X 7bit: 0x%X\n", address, address << 1);
00016             nDevices++;
00017         }
00018     }
00019     if (nDevices == 0){
00020         printf("No I2C devices found\n");
00021     }else{
00022         printf("\ndone\n");
00023     }
00024 }