MULTIPLE SCREENS IN 1 LCD 16X2 I2C LCD DISPLAY || DISPLAY ALL SENSORS FEEDBACK
CIRCUIT:
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x3F,16,2);//Default address is 0x27
int page_counter=1 ; //To move beetwen pages
//-------Pins-----//
int up = 2; //Up button
int down = 3; //Down button
//---------Storage debounce function-----//
boolean current_up = LOW;
boolean last_up = LOW;
boolean last_down = LOW;
boolean current_down = LOW;
void setup() {
lcd.init();
lcd.backlight();
}
//---- De-bouncing function for all buttons----//
boolean debounce(boolean last, int pin)
{
boolean current = digitalRead(pin);
if (last != current)
{
delay(5);
current = digitalRead(pin);
}
return current;
}
void loop() {
MULTIPLE_SCREENS();
}
void MULTIPLE_SCREENS() {
current_up = debounce(last_up, up); //Debounce for Up button
current_down = debounce(last_down, down); //Debounce for Down button
//----Page counter function to move pages----//
//Page Up
if (last_up == LOW && current_up == HIGH){ //When up button is pressed
lcd.clear(); //When page is changed, lcd clear to print new page
if(page_counter <5){ //Page counter never higher than 3(total of pages)
page_counter = page_counter +1; //Page up
}
else{
page_counter = 5; //NUMBER OF SCREENS/PAGES
}
}
last_up = current_up;
//Page Down
if (last_down == LOW && current_down == HIGH){ //When down button is pressed
lcd.clear(); //When page is changed, lcd clear to print new page
if(page_counter >1){ //Page counter never lower than 1 (total of pages)
page_counter = page_counter -1; //Page down
}
else{
page_counter = 1;
}
}
last_down = current_down;
//------- Switch function to write and show what you want---//
switch (page_counter) {
case 1:{ //Design of HOME SCREEN 1
lcd.setCursor(0,0);
lcd.print("MK_INVENTIONS");
lcd.setCursor(15,0);
lcd.print("1");
lcd.setCursor(4,1);
lcd.print("SCREEN 1");
}
break;
case 2: { //Design of SCREEN 2
lcd.setCursor(0,0);
lcd.print("MADHAN KUMAR");
lcd.setCursor(15,0);
lcd.print("2");
lcd.setCursor(4,1);
lcd.print("SCREEN 2");
}
break;
case 3: { //Design of SCREEN 3
lcd.setCursor(0,0);
lcd.print("CHIRUGURI");
lcd.setCursor(15,0);
lcd.print("3");
lcd.setCursor(4,1);
lcd.print("SCREEN 3");
}
break;
case 4: { //Design of SCREEN 4
lcd.setCursor(0,0);
lcd.print("HELLO! WORLD");
lcd.setCursor(15,0);
lcd.print("4");
lcd.setCursor(4,1);
lcd.print("SCREEN 4");
}
break;
case 5: { //Design of SCREEN 5
lcd.setCursor(0,0);
lcd.print("WELCOME");
lcd.setCursor(15,0);
lcd.print("5");
lcd.setCursor(4,1);
lcd.print("SCREEN 5");
}
break;
}//switch end
}//loop end
SOURCE CODE 2 FOR SERVO AND POTENTIOMETER VALUES:
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include<Servo.h>
Servo servo1;
LiquidCrystal_I2C lcd(0x3F,16,2);//Default address is 0x27
int page_counter=1 ; //To move beetwen pages
int POTVALUE;
//-------Pins-----//
int up = 2; //Up button
int down = 3; //Down button
//---------Storage debounce function-----//
boolean current_up = LOW;
boolean last_up = LOW;
boolean last_down = LOW;
boolean current_down = LOW;
void setup() {
lcd.init();
lcd.backlight();
servo1.attach(10);
pinMode(A0, INPUT);
}
//---- De-bouncing function for all buttons----//
boolean debounce(boolean last, int pin)
{
boolean current = digitalRead(pin);
if (last != current)
{
delay(5);
current = digitalRead(pin);
}
return current;
}
void loop() {
int POTENTIOMETER = analogRead(A0);
int POTVALUE = map(POTENTIOMETER, 0, 1023, 0, 180);
servo1.write(POTVALUE);
current_up = debounce(last_up, up); //Debounce for Up button
current_down = debounce(last_down, down); //Debounce for Down button
//----Page counter function to move pages----//
//Page Up
if (last_up == LOW && current_up == HIGH){ //When up button is pressed
lcd.clear(); //When page is changed, lcd clear to print new page
if(page_counter <5){ //Page counter never higher than 3(total of pages)
page_counter = page_counter +1; //Page up
}
else{
page_counter = 5; //NUMBER OF SCREENS/PAGES
}
}
last_up = current_up;
//Page Down
if (last_down == LOW && current_down == HIGH){ //When down button is pressed
lcd.clear(); //When page is changed, lcd clear to print new page
if(page_counter >1){ //Page counter never lower than 1 (total of pages)
page_counter = page_counter -1; //Page down
}
else{
page_counter = 1;
}
}
last_down = current_down;
//------- Switch function to write and show what you want---//
switch (page_counter) {
case 1:{ //Design of HOME SCREEN 1
lcd.setCursor(0,0);
lcd.print("MK_INVENTIONS");
lcd.setCursor(15,0);
lcd.print("1");
lcd.setCursor(4,1);
lcd.print("SCREEN 1");
}
break;
case 2: { //Design of SCREEN 2
lcd.setCursor(0,0);
lcd.print("MADHAN KUMAR");
lcd.setCursor(15,0);
lcd.print("2");
lcd.setCursor(4,1);
lcd.print("SCREEN 2");
}
break;
case 3: { //Design of SCREEN 3
lcd.setCursor(0,0);
lcd.print("CHIRUGURI");
lcd.setCursor(15,0);
lcd.print("3");
lcd.setCursor(4,1);
lcd.print("SCREEN 3");
}
break;
case 4: { //Design of SCREEN 4
lcd.setCursor(0,0);
lcd.print("HELLO! WORLD");
lcd.setCursor(15,0);
lcd.print("4");
lcd.setCursor(4,1);
lcd.print("SCREEN 4");
}
break;
case 5: { //Design of SCREEN 5
lcd.setCursor(0,0);
lcd.print("SERVO1:");
lcd.setCursor(7,0);
lcd.print(POTVALUE);
lcd.setCursor(15,0);
lcd.print("5");
lcd.setCursor(4,1);
lcd.print("SCREEN 5");
}
break;
}//switch end
}//loop end
0 Comments
Please do not Enter any Spam Link in the Comment Box
Emoji