JAM dengan LCD16x2 Karakter Besar

kali ini penulis mencoba hal simpel, membuat jam dengan LCD 16×2 tetapi karakter yg ditampilkan berukuran besar 😀 penulis mengunakan Arduino dan DFrobo LCD Keyped Shield. ok langsung saja ini hasil nya 😀

WP_20150206_019_600

coding yg sy buat tidak mengunakan RTC jadi bila ingin mengunakan RTC silahkan modif sendiri code arduino berikut :D:

//**********************************************************
// DEMO JAM KARAKTER BESAR :D TANPA RTC
//**********************************************************

#include <LiquidCrystal.h>
#include <Timer.h>

//**********************************************************

#define LCD_CHAR_UNFULL 	0
#define LCD_CHAR_FULL 		1
#define LCD_CHAR_TOP 		2
#define LCD_CHAR_TOP_BOTTOM 3
#define LCD_CHAR_BOTTOM 	4
#define LCD_CHAR_DOT_1 		5
#define LCD_CHAR_DOT_2 		6
#define LCD_CHAR_STRIP 		7

//**********************************************************

byte charLcd1[8] = { B00000, B00000, B00000, B00000, B00000, B00000, B00000, B00000 };
byte charLcd2[8] = { B11111, B11111, B11111, B11111, B11111, B11111, B11111, B11111 };
byte charLcd3[8] = { B11111, B11111, B00000, B00000, B00000, B00000, B00000, B00000 };
byte charLcd4[8] = { B11111, B11111, B00000, B00000, B00000, B00000, B11111, B11111 };
byte charLcd5[8] = { B00000, B00000, B00000, B00000, B00000, B00000, B11111, B11111 };
byte charLcd6[8] = { B00000, B00000, B00011, B00011, B00011, B00011, B00000, B00000 };
byte charLcd7[8] = { B00000, B00000, B11000, B11000, B11000, B11000, B00000, B00000 };
byte charLcd8[8] = { B00000, B00000, B00000, B11111, B11111, B00000, B00000, B00000 };

// otomatis akan terisi waktu dari PC saat program di upload
//**********************************************************
char* waktuDariPC = __TIME__;
//**********************************************************

int ss = 0;
int mm = 0;
int hh = 0;
boolean titikDua = true;

//**********************************************************

LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
Timer t;

//**********************************************************

void setup() {
 	lcd.begin(16, 2);              

    lcd.createChar(LCD_CHAR_UNFULL, charLcd1);
    lcd.createChar(LCD_CHAR_FULL, 	charLcd2);
    lcd.createChar(LCD_CHAR_TOP, 	charLcd3);
    lcd.createChar(LCD_CHAR_TOP_BOTTOM, charLcd4);
    lcd.createChar(LCD_CHAR_BOTTOM, charLcd5);
    lcd.createChar(LCD_CHAR_DOT_1, 	charLcd6);
    lcd.createChar(LCD_CHAR_DOT_2, 	charLcd7);
    lcd.createChar(LCD_CHAR_STRIP, 	charLcd8);

	hh = setringKeInt( String(waktuDariPC[0]) + String(waktuDariPC[1]) );
	mm = setringKeInt( String(waktuDariPC[3]) + String(waktuDariPC[4]) );
	ss = setringKeInt( String(waktuDariPC[6]) + String(waktuDariPC[7]) );

    int e = t.every(1000, doTimer);
}

//**********************************************************

int setringKeInt(String str){ return str.toInt();}

//**********************************************************

void doTimer(){
	ss++;
	if(ss>59){
		ss=0; mm++;
		if(mm>59){
			mm=0; hh++;
			if(hh>59){
				hh=0;
			}
		}
	}

	titikDua = titikDua==true ? false : true;

	cetak2digitKarakterBesar(hh, 0);
	if(titikDua){
		lcd.setCursor(7, 0);
		lcdDot();

		lcd.setCursor(7, 1);
		lcdDot();
	}else{
		lcd.setCursor(7, 0);
		lcdUnDot();

		lcd.setCursor(7, 1);
		lcdUnDot();
	}
	cetak2digitKarakterBesar(mm, 9);
}

//**********************************************************

void lcdDot(){
	lcd.write(byte(LCD_CHAR_DOT_1));
	lcd.write(byte(LCD_CHAR_DOT_2));
}

//**********************************************************

void lcdUnDot(){
	lcd.write(byte(LCD_CHAR_UNFULL));
	lcd.write(byte(LCD_CHAR_UNFULL));
}

//**********************************************************

void cetak2digitKarakterBesar(byte n, byte pos){
	byte puluhan = n / 10;
	byte satuan  = n - (puluhan * 10);

	cetakKarakterBesar(puluhan, pos);
	cetakKarakterBesar(satuan, pos+4);
}

//**********************************************************

void cetakKarakterBesar(byte n, byte pos){
	switch (n) {
		case 1:
			lcd.setCursor(0+pos, 0);
			lcd.write(byte(LCD_CHAR_TOP)); //* TOP
			lcd.write(byte(LCD_CHAR_FULL));
			lcd.write(byte(LCD_CHAR_UNFULL));

			lcd.setCursor(0+pos, 1);
			lcd.write(byte(LCD_CHAR_BOTTOM));
			lcd.write(byte(LCD_CHAR_FULL));
			lcd.write(byte(LCD_CHAR_BOTTOM));
		break;
		case 2:
			lcd.setCursor(0+pos, 0);
			lcd.write(byte(LCD_CHAR_TOP_BOTTOM));
			lcd.write(byte(LCD_CHAR_TOP_BOTTOM));
			lcd.write(byte(LCD_CHAR_FULL));

			lcd.setCursor(0+pos, 1);
			lcd.write(byte(LCD_CHAR_FULL));
			lcd.write(byte(LCD_CHAR_TOP_BOTTOM));
			lcd.write(byte(LCD_CHAR_TOP_BOTTOM));
		break;
		case 3:
			lcd.setCursor(0+pos, 0);
			lcd.write(byte(LCD_CHAR_TOP_BOTTOM));
			lcd.write(byte(LCD_CHAR_TOP_BOTTOM));
			lcd.write(byte(LCD_CHAR_FULL));

			lcd.setCursor(0+pos, 1);
			lcd.write(byte(LCD_CHAR_TOP_BOTTOM));
			lcd.write(byte(LCD_CHAR_TOP_BOTTOM));
			lcd.write(byte(LCD_CHAR_FULL));
		break;
		case 4:
			lcd.setCursor(0+pos, 0);
			lcd.write(byte(LCD_CHAR_FULL));
			lcd.write(byte(LCD_CHAR_BOTTOM));
			lcd.write(byte(LCD_CHAR_FULL));

			lcd.setCursor(0+pos, 1);
			lcd.write(byte(LCD_CHAR_TOP)); //* TOP
			lcd.write(byte(LCD_CHAR_TOP));
			lcd.write(byte(LCD_CHAR_FULL));
		break;
		case 5:
			lcd.setCursor(0+pos, 0);
			lcd.write(byte(LCD_CHAR_FULL));
			lcd.write(byte(LCD_CHAR_TOP_BOTTOM));
			lcd.write(byte(LCD_CHAR_TOP_BOTTOM));
			
			lcd.setCursor(0+pos, 1);
			lcd.write(byte(LCD_CHAR_TOP_BOTTOM));
			lcd.write(byte(LCD_CHAR_TOP_BOTTOM));
			lcd.write(byte(LCD_CHAR_FULL));
		break;
		case 6:
			lcd.setCursor(0+pos, 0);
			lcd.write(byte(LCD_CHAR_FULL));
			lcd.write(byte(LCD_CHAR_TOP_BOTTOM));
			lcd.write(byte(LCD_CHAR_TOP_BOTTOM));
			
			lcd.setCursor(0+pos, 1);
			lcd.write(byte(LCD_CHAR_FULL));
			lcd.write(byte(LCD_CHAR_TOP_BOTTOM));
			lcd.write(byte(LCD_CHAR_FULL));
		break;
		case 7:
			lcd.setCursor(0+pos, 0);
			lcd.write(byte(LCD_CHAR_TOP)); //* TOP
			lcd.write(byte(LCD_CHAR_TOP));
			lcd.write(byte(LCD_CHAR_FULL));
			
			lcd.setCursor(0+pos, 1);
			lcd.write(byte(LCD_CHAR_UNFULL));
			lcd.write(byte(LCD_CHAR_UNFULL));
			lcd.write(byte(LCD_CHAR_FULL));
		break;
		case 8:
			lcd.setCursor(0+pos, 0);
			lcd.write(byte(LCD_CHAR_FULL));
			lcd.write(byte(LCD_CHAR_TOP_BOTTOM));
			lcd.write(byte(LCD_CHAR_FULL));

			lcd.setCursor(0+pos, 1);
			lcd.write(byte(LCD_CHAR_FULL));
			lcd.write(byte(LCD_CHAR_TOP_BOTTOM));
			lcd.write(byte(LCD_CHAR_FULL));
		break;
		case 9:
			lcd.setCursor(0+pos, 0);
			lcd.write(byte(LCD_CHAR_FULL));
			lcd.write(byte(LCD_CHAR_TOP_BOTTOM));
			lcd.write(byte(LCD_CHAR_FULL));

			lcd.setCursor(0+pos, 1);
			lcd.write(byte(LCD_CHAR_TOP_BOTTOM));
			lcd.write(byte(LCD_CHAR_TOP_BOTTOM));
			lcd.write(byte(LCD_CHAR_FULL));
		break;
		case 0:
			lcd.setCursor(0+pos, 0);
			lcd.write(byte(LCD_CHAR_FULL));
			lcd.write(byte(LCD_CHAR_TOP));
			lcd.write(byte(LCD_CHAR_FULL));

			lcd.setCursor(0+pos, 1);
			lcd.write(byte(LCD_CHAR_FULL));
			lcd.write(byte(LCD_CHAR_BOTTOM));
			lcd.write(byte(LCD_CHAR_FULL));
		break;
	}
}

//**********************************************************

void loop() { t.update(); }

Iklan
Perihal

Pemancar FM, Penerima FM, Microcontroler

Ditulis dalam Arduino, Microcontroller
%d blogger menyukai ini: