CARA MEMPROGRAM LCD KARAKTER KEYPAD SHIELD 16X2 DENGAN ARDUINO

LCD KARAKTER KEYPAD SHIELD 16X2
Pada posting kali ini kita akan membahas Tutorial Cara Memprogram Lcd Keypad Karakter 16X2 Dengan Arduino,di arduino untuk lcd karakter sudah tersedia librarynya.

Untuk mencoba tutorial ini,modul yang di butuhkan :
1.Arduino Uno
2.LCD Keypad Shield

DIAGRAM
DIAGRAM LCD KARAKTER KEYPAD SHIELD 16X2


ALOKASI PIN ARDUINO


Keypad Shield Arduino

PIN LCD KARAKTER KEYPAD SHIELD 16X2

CONTOH PROGRAM

/*******************************************************
Program : LCD KARAKTER KEYPAD SHIELD 16X2
Chip : Arduino Uno
Date : 25/06/2015
Created : Mark Bramwell
Modified : Lab-elektronika Team
email : elektronikajakarta@gmail.com
Sumber : labelektronika.blogspot.com
********************************************************/
#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

int tombollcd = 0;
int bacatombol = 0;
#define tombolright 0
#define tombolup 1
#define tomboldown 2
#define tombolleft 3
#define tombolselect 4
#define tombolnone 5

int read_LCD_buttons()
{
bacatombol = analogRead(0);
if (bacatombol > 1000) return tombolnone;
if (bacatombol < 50) return tombolright;
if (bacatombol < 250) return tombolup;
if (bacatombol < 450) return tomboldown;
if (bacatombol < 650) return tombolleft;
if (bacatombol < 850) return tombolselect;
return tombolnone;
}

void setup()
{
lcd.begin(16, 2);
lcd.setCursor(0,0);
lcd.print("TEKAN TOMBOL");
}

void loop()
{
lcd.setCursor(0,1);
tombollcd = read_LCD_buttons();

switch (tombollcd)
{
case tombolright:
{
lcd.print("RIGHT ");
break;
}
case tombolleft:
{
lcd.print("LEFT ");
break;
}
case tombolup:
{
lcd.print("UP ");
break;
}
case tomboldown:
{
lcd.print("DOWN ");
break;
}
case tombolselect:
{
lcd.print("SELECT");
break;
}
case tombolnone:
{
lcd.print("NONE ");
break;
}
}

}


PENJELASAN PROGRAM 
  • Panggil library lcd untuk arduino
#include <LiquidCrystal.h>
  • Inisialisasi pin arduino yg di gunakan
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
  • Mendefinisikan nilai variabel
int tombollcd  = 0;
int bacatombol = 0;
#define tombolright 0
#define tombolup 1
#define tomboldown 2
#define tombolleft 3
#define tombolselect 4
#define tombolnone 5
  • Fungsi baca tombol dengan adc
int read_LCD_buttons()
{
bacatombol = analogRead(0);
if (bacatombol > 1000) return tombolnone;
if (bacatombol < 50) return tombolright;
if (bacatombol < 250) return tombolup;
if (bacatombol < 450) return tomboldown;
if (bacatombol < 650) return tombolleft;
if (bacatombol < 850) return tombolselect;
return tombolnone;
}
  • Tampilkan karakter ke lcd
 lcd.print("TEKAN TOMBOL");
  • Set posisi kolom dan baris
 lcd.setCursor(0,0); 
 lcd.setCursor(0,1);   
  • Baca tombol ditekan
tombollcd = read_LCD_buttons(); 

No comments for "CARA MEMPROGRAM LCD KARAKTER KEYPAD SHIELD 16X2 DENGAN ARDUINO"