아두이노 128x64 LCD 쉴드 -5방향 조이스틱 장착
(128x64 LCD Shield for Arduino)
개요
- 본 제품은 128x64 모노크롬 LCD를 장착한 아두이노 쉴드입니다.
- 영어나 숫자 문자열을 여러줄에 걸쳐 표시할 수 있으며, 5방향 조이스틱(좌우상하, 누름)이 장착되어 있어 메뉴등을 디스플레이하고 조이스틱을 이용하여 스크롤 선택하는 어플리케이션에 적합한 제품입니다.
- LCD 컨트롤러는 UC1701x입니다.
- U8glib library 를 이용하여 사용이 가능합니다.
특징
- n/a
문서
- Schematic
- LCD
- U8glib library
- ardunio code
#include "U8glib.h" U8GLIB_NHD_C12864 u8g(13, 11, 10, 9, 8); // SPI Com: SCK = 13, MOSI = 11, CS = 10, CD = 9, RST = 8 void draw(void) { // graphic commands to redraw the complete screen should be placed here u8g.setFont(u8g_font_unifont); //u8g.setFont(u8g_font_osb21); u8g.drawStr( 0, 20, "Arduion LCD"); } void setup(void) { u8g.setContrast(0); // Config the contrast to the best effect u8g.setRot180();// rotate screen, if required // set SPI backup if required //u8g.setHardwareBackup(u8g_backup_avr_spi); // assign default color value if ( u8g.getMode() == U8G_MODE_R3G3B2 ) { u8g.setColorIndex(255); // white } else if ( u8g.getMode() == U8G_MODE_GRAY2BIT ) { u8g.setColorIndex(3); // max intensity } else if ( u8g.getMode() == U8G_MODE_BW ) { u8g.setColorIndex(1); // pixel on } else if ( u8g.getMode() == U8G_MODE_HICOLOR ) { u8g.setHiColorByRGB(255,255,255); } } void loop(void) { // picture loop u8g.firstPage(); do { draw(); } while( u8g.nextPage() ); // rebuild the picture after some delay delay(500); }
-
Wiring
- U8GLIB_NHD_C12864 u8g(13, 11, 10, 9, 8); // SPI Com: SCK = 13, MOSI = 11, CS = 10, CD = 9, RST = 8
Arduino LCD12864 D13 SCK D11 SDA 3V3 VDD, LEDA GND VSS D10 CS D8 RST D9 RS - example code (menu) contrast 설정값 체크 필요.
#include "U8glib.h" // setup u8g object, please remove comment from one of the following constructor calls // IMPORTANT NOTE: The complete list of supported devices is here: http://code.google.com/p/u8glib/wiki/device U8GLIB_NHD_C12864 u8g(13, 11, 10, 9, 8); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9, RST = 8 #define KEY_NONE 0 #define KEY_PREV 1 #define KEY_NEXT 2 #define KEY_SELECT 3 #define KEY_BACK 4 uint8_t uiKeyCodeFirst = KEY_NONE; uint8_t uiKeyCodeSecond = KEY_NONE; uint8_t uiKeyCode = KEY_NONE; int adc_key_in; int key=-1; int oldkey=-1; // Convert ADC value to key number // 4 // | // 0 -- 1 -- 3 // | // 2 int get_key(unsigned int input) { if (input < 10) return 4; else if (input < 200) return 0; else if (input < 400) return 2; else if (input < 600) return 1; else if (input < 800) return 3; else return -1; } void uiStep(void) { adc_key_in = analogRead(0); // read the value from the sensor key = get_key(adc_key_in); // convert into key press if (key != oldkey) // if keypress is detected { delay(50); // wait for debounce time adc_key_in = analogRead(0); // read the value from the sensor key = get_key(adc_key_in); // convert into key press if (key != oldkey) { oldkey = key; if (key >=0){ //Serial.println(key); if ( key == 0 ) uiKeyCodeFirst = KEY_BACK; else if ( key == 1 ) uiKeyCodeFirst = KEY_SELECT; else if ( key == 2 ) uiKeyCodeFirst = KEY_NEXT; else if ( key == 4 ) uiKeyCodeFirst = KEY_PREV; else uiKeyCodeFirst = KEY_NONE; uiKeyCode = uiKeyCodeFirst; } } } delay(100); } #define MENU_ITEMS 6 char *menu_strings[MENU_ITEMS] = { "LCD12864 Shield", "Dust status", "Temperature", "Humidity" ,"About","OK"}; uint8_t menu_current = 0; uint8_t menu_redraw_required = 0; uint8_t last_key_code = KEY_NONE; void drawMenu(void) { uint8_t i, h; u8g_uint_t w, d; u8g.setFont(u8g_font_6x12);//4x6 5x7 5x8 6x10 6x12 6x13 u8g.setFontRefHeightText(); u8g.setFontPosTop(); h = u8g.getFontAscent()-u8g.getFontDescent(); w = u8g.getWidth(); for( i = 0; i < MENU_ITEMS; i++ ) { d = (w-u8g.getStrWidth(menu_strings[i]))/2; u8g.setDefaultForegroundColor(); if ( i == menu_current ) { u8g.drawBox(0, i*h+1, w, h); u8g.setDefaultBackgroundColor(); } u8g.drawStr(d, i*h+1, menu_strings[i]); } } void updateMenu(void) { switch ( uiKeyCode ) { case KEY_NEXT: menu_current++; if ( menu_current >= MENU_ITEMS )menu_current = 0; menu_redraw_required = 1; break; case KEY_PREV: if ( menu_current == 0 )menu_current = MENU_ITEMS; menu_current--; menu_redraw_required = 1; break; } uiKeyCode = KEY_NONE; } void setup() { u8g.setContrast(0); u8g.setRot180();// rotate screen, if required menu_redraw_required = 1; // force initial redraw //Serial.begin(9600); } void loop() { uiStep(); // check for key press updateMenu(); // update menu bar if ( menu_redraw_required != 0 ) { u8g.firstPage(); do { drawMenu(); } while( u8g.nextPage() ); menu_redraw_required = 0; } }