Challenge

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

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

// C++ code
//slave
#include<LiquidCrystal.h>
#include<Wire.h>
LiquidCrystal lcd(12,11,5,4,3,2);
void setup()
//void setup()
{
//Serial.begin(9600);
Wire.begin(8);
// LiquidCrystal lcd(rs,enable,lcd,d5,d6,d7);
// LiquidCrystal lcd(12,11,5,4,3,2);
lcd.begin(16,2);
Wire.onReceive(display);
}

void loop()
{
delay(30);
}
void display(int y)
{
int x=Wire.read();
lcd.setCursor(0,0);

lcd.print("I got the value of : ");
lcd.print(x);
lcd.println();
delay(1000);
}

//master

//Serial.print(x);
// C++ code
//master
#include<Wire.h>

void setup()
{
pinMode(A0,INPUT);
Wire.begin();


}

void loop()
{

float x=analogRead(A0);
signed int value=((x*5)/1024);
//int temp=((value-0.5)*100);
Wire.beginTransmission(8);
Wire.write(value);
Wire.endTransmission();
delay(1000); // Wait for 1000 millisecond(s)
}

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.