Project 1 - Interfacing a 16*2 LCD with Arduino using I2C protocol
1a)
Slave.
#include<Wire.h>
#include<LiquidCrystal.h>
LiquidCrystal lcd(13,12,5,4,3,2);
void setup()
{
Serial.begin(9600);
lcd.begin(16,2);
Wire.begin(1);
Wire.onReceive(myfunction);
}
void myfunction(int p)
{
int a=Wire.read();
lcd.setCursor(4,0);
lcd.print(a);
delay(500);
}
void loop()
{
}
1b).
Master.
#include<Wire.h>
void setup()
{
Serial.begin(9600);
Serial.println("master");
Wire.begin();
}
void loop()
{
int mydata=5;
Wire.beginTransmission(1);
Wire.write(mydata);
Wire.endTransmission();
}
Link: https://www.tinkercad.com/things/jGxmQOPRJd2-i2c-project-1/editel?sharecode=30KeEExm1KzNoW2Um_uQGSIMkk0lbJgmeOmupwnGBMk