Challenge

Project 1 - Interfacing a 16*2 LCD with Arduino using I2C protocol

//* P1: Code for Master to receive name and display on LCD *//

#include
#include
LiquidCrystal lcd(6,7,2,3,4,5);
#define SLAVE_ADDR 8
#define NameSize 20

void setup()
{
Wire.begin();
lcd.begin(16,2);
Serial.begin(9600);
}

void loop()
{
Wire.requestFrom(SLAVE_ADDR,NameSize);
String MyName="";
while(Wire.available())
{
char b=Wire.read();
MyName+=b;
}
lcd.setCursor(0,0);
lcd.print(MyName);
Serial.println(MyName);
}

//* P1:Code for Slave to transmission of name to Master *//

#include
#include
LiquidCrystal lcd(6,7,2,3,4,5);
#define SLAVE_ADDR 8
#define NameSize 20
String Name="amol, skill-lync";


void setup()
{
Wire.begin(SLAVE_ADDR);
Wire.onRequest(requestEvent);
Serial.begin(9600);
}

void requestEvent()
{
byte MyName[NameSize];
for(int i=0;i<20>{
MyName[i]=(byte)Name.charAt(i);
}
Wire.write(MyName,sizeof(MyName));
}

void loop()
{
delay(500);
}

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.