Created
January 26, 2012 23:21
-
-
Save eduardodx/1685786 to your computer and use it in GitHub Desktop.
Arduino - I2C Master
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <LiquidCrystal.h> | |
#include <Wire.h> | |
int x, y, resposta = 0; | |
LiquidCrystal lcd(2, 3, 4, 5, 6, 7); | |
void setup() { | |
lcd.begin(16, 2); | |
lcd.home(); | |
Wire.begin();// Inicia a comunicação I2C, o Master não precisa de endereço | |
} | |
void loop(){ | |
x++; | |
if (x >1000) x=0; | |
randomSeed (x); | |
y = random (256); | |
Wire.beginTransmission (2);//inicia a transmissão com o dispositivo 2 | |
Wire.send (y);// envia o valor de y | |
Wire.requestFrom (2, 1);// requisita 1 byte do dispositivo 2 | |
resposta = Wire.receive();// lê o byte requisitado | |
Wire.endTransmission();// finaliza a transmição de dados | |
lcd.clear();// escreve os dados no lcd | |
lcd.home(); | |
lcd.print (y); | |
lcd.setCursor (0, 1); | |
lcd.print(resposta); | |
delay (1000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment