Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Ejercicio 62
  • Loading branch information
jecrespo committed Nov 15, 2016
1 parent 6a7c94f commit 5e14dea
Show file tree
Hide file tree
Showing 4 changed files with 1,344 additions and 0 deletions.
37 changes: 37 additions & 0 deletions Ejercicio33-I2C/scanI2CBus/scanI2CBus.ino
@@ -0,0 +1,37 @@
#include "Wire.h"
extern "C" {
#include "utility/twi.h"
}
void scanI2CBus(byte from_addr, byte to_addr, void(*callback)(byte address, byte result) )
{
byte rc;
byte data = 0;
for( byte addr = from_addr; addr <= to_addr; addr++ ) {
rc = twi_writeTo(addr, &data, 0, 1, 0);
callback( addr, rc );
}
}
void scanFunc( byte addr, byte result ) {
Serial.print("addr: ");
Serial.print(addr,DEC);
Serial.print( (result==0) ? " Encontrado!":" ");
Serial.print( (addr%4) ? "\t":"\n");
}


const byte start_address = 8;
const byte end_address = 119;

void setup()
{
Wire.begin();
Serial.begin(9600);
Serial.print("Escaneando bus I2C...");
scanI2CBus( start_address, end_address, scanFunc );
Serial.println("\nTerminado");
}

void loop()
{
delay(1000);
}

0 comments on commit 5e14dea

Please sign in to comment.