Project 1 - Interfacing a 16*2 LCD with Arduino using I2C protocol
EMBEDDED OFFLINE BATCH:
Interfacing a 16*2 LCD with Arduino using I2C protocol:
//MASTER
#include<Wire.h>
#include<LiquidCrystal.h>
void setup()
{
LiquidCrystal lcd(12,11,5,4,3,2);
lcd.begin(16,2);
Serial.begin(9600);
Wire.begin(8);
Wire.onReceive(display);
}
void loop()
{
delay(30);
}
void display(int x)
{
LiquidCrystal lcd(12,11,5,4,3,2);
int y=Wire.read();
Serial.println(y);
lcd.setCursor(1,0);
lcd.print("the volt is");
lcd.print(y);
delay(1000);
}
//SLAVE:
#include<Wire.h>
void setup()
{
Serial.begin(9600);
Wire.begin();
pinMode(A0,INPUT);
}
void loop()
{
float x=analogRead(A0);
float value=((x*5)/1024);
signed int temp=((value-0.5)*100);
Wire.beginTransmission(8);
Wire.write(temp);
Wire.endTransmission();
//Serial.println(temp);
delay(1000);
}