0% found this document useful (0 votes)
36 views

Code Program Keypad Karya Ing

This document contains code for an Arduino project that controls 4 devices and displays their on/off status using a keypad and LCD screen. It initializes libraries for the keypad, LCD screen and digital pins. In setup, it configures the LCD and pin modes. The main loop scans the keypad, updates the device statuses and LCD accordingly. Pressing keys 1-4 toggle the individual devices, 0 turns all off, and # turns all on.
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views

Code Program Keypad Karya Ing

This document contains code for an Arduino project that controls 4 devices and displays their on/off status using a keypad and LCD screen. It initializes libraries for the keypad, LCD screen and digital pins. In setup, it configures the LCD and pin modes. The main loop scans the keypad, updates the device statuses and LCD accordingly. Pressing keys 1-4 toggle the individual devices, 0 turns all off, and # turns all on.
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

//https://www.youtube.

com/channel/UCiqQohXiRid9g3-Wk2KgE0Q
// This project is done by Teach Me Something
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Keypad.h>

int device1 =10;


int device2 =11;
int device3 =12;
int device4 =13;
boolean device1sts =HIGH;
boolean device2sts =HIGH;
boolean device3sts =HIGH;
boolean device4sts =HIGH;

LiquidCrystal_I2C lcd(0x27, 16, 2); // 3F is not working then change the valus as
27

const byte ROWS = 4; //four rows


const byte COLS = 4; //four columns
//define the cymbols on the buttons of the keypads
char hexaKeys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte rowPins[ROWS] = {9,8,7,6}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {5,4,3,2}; //connect to the column pinouts of the keypad

//initialize an instance of class NewKeypad


Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);

void setup(){
Serial.begin(9600);
digitalWrite(device1,HIGH);
digitalWrite(device2,HIGH);
digitalWrite(device3,HIGH);
digitalWrite(device4,HIGH);
lcd.begin();//lcd.init
lcd.clear();
lcd.backlight();
lcd.setCursor(1,0);
lcd.print("Welcome");
lcd.setCursor(0,1);
lcd.print("YouTube KARYAING");
delay(3000);
lcd.clear();
pinMode(device1,OUTPUT);
pinMode(device2,OUTPUT);
pinMode(device3,OUTPUT);
pinMode(device4,OUTPUT);

void loop(){

digitalWrite(device1,device1sts);
digitalWrite(device2,device2sts);
digitalWrite(device3,device3sts);
digitalWrite(device4,device4sts);

lcd.setCursor(0,0);
lcd.print(" D1 D2 D3 D4 ");
lcd.setCursor(0,1);//1
if(device1sts)
lcd.print(" OFF ");
else
lcd.print(" ON ");

lcd.setCursor(4,1);//5
if(device2sts)
lcd.print(" OFF ");
else
lcd.print(" ON ");

lcd.setCursor(8,1);//9
if(device3sts)
lcd.print(" OFF ");
else
lcd.print(" ON ");;

lcd.setCursor(12,1);//13
if(device4sts)
lcd.print(" OFF ");
else
lcd.print(" ON ");

char customKey = customKeypad.getKey();

if (customKey){

if (customKey == '0')
{
device1sts=HIGH;
device2sts=HIGH;
device3sts=HIGH;
device4sts=HIGH;
}
//=====================
if (customKey == '#')
{
device1sts=LOW;
device2sts=LOW;
device3sts=LOW;
device4sts=LOW;
}
else if (customKey =='1')
device1sts=!device1sts;
else if (customKey =='2')
device2sts=!device2sts;
else if (customKey =='3')
device3sts=!device3sts;
else if (customKey =='4')
device4sts=!device4sts;
else
{
lcd.setCursor(0,0);
lcd.print("Enter Valid Key");
}

}
}

You might also like