/* e-Gizmo LCD Shield & keypad shield v1 (16x2 with 4x4 Keypad Module for Gizduino 168/328) This is a simple sample code for the sample demonstration of LCD (2x16),(4x20) Display and keypad matrix connections. Also with on board buttons and a +5v buzzer included. This LCD Shield is compatible in gizDuino (plus) ATmega644p and gizDuino (x) ATmega1281p.(Manual wiring for Gizduino 328P please see the manual for the conections) The circuit: *gizDuino 328 == 644 and X * LCD RS pin to digital pin 12 == pin 26 * LCD Enable pin to digital pin 11 == pin 27 * LCD D4 pin to digital pin 5 == pin 28 * LCD D5 pin to digital pin 4 == pin 29 * LCD D6 pin to digital pin 3 == pin 30 * LCD D7 pin to digital pin 2 == pin 31 * LCD R/W pin to ground * LCD VSS pin to ground * LCD VCC pin to 5V * 10K resistor: * ends to +5V and ground * wiper to LCD VO pin (pin 3) Library originally added 18 Apr 2008 by David A. Mellis library modified 5 Jul 2009 by Limor Fried (http://www.ladyada.net) example added 9 Jul 2009 by Tom Igoe modified 22 Nov 2010 by Tom Igoe This example code is in the public domain. http://www.arduino.cc/en/Tutorial/LiquidCrystal /--------------------------------------------------------------/ AlphaNumericKeypad - This code converts 4x4 keypad module into an alphanumeric keypad. Vesion: 1.0 Coded by: Jose @: e-Gizmo On: 02 MAY 2014 Keymap: [1] [2] [3] [A] .,!@... abc def Backspace [4] [5] [6] [B] ghi jkl mno [7] [8] [9] [C] pqrs tuv wxyz [*] [0] [#] [D] space Normal press: Toggle CapsLock HOLD: Toggle Number/Letters References: EventSerialKeypad.pde by Alexander Brevig DynamicKeypad.pde by Mark Stanley by e-Gizmo Mechatronix Central http://www.e-gizmo.com November 12, 2015 modified */ #include #include //Selection of LiquidCrystal pins LiquidCrystal lcd(12, 11, 5, 4, 3, 2); //gizDuino 328 or gizduino V //LiquidCrystal lcd(26, 27, 28, 29, 30, 31); //default pin assign (644 and X) const byte ROWS = 4; //four rows const byte COLS = 4; //four columns char keys[ROWS][COLS] = { {'1','2','3','A'} , {'4','5','6','B'} , {'7','8','9','C'} , {'*','0','#','D'} }; //default pin for 4x3 (remove COL 23) and 4x4 keypad Matrix (add COL 23) byte rowPins[ROWS] = {14, 15, 16, 17}; //connect to the row pinouts of the keypad byte colPins[COLS] = {7, 8, 9, 10}; //connect to the column pinouts of the keypad Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS ); char stringBuff[21]; char letters [27]; char symbols [30] = ".,'?!\"-()@/:_;+&%*=<>[]{}~^# "; char selchar; char keypressed; char previous; boolean num = false; boolean caps = false; unsigned long pressTime; unsigned long releaseTime; int ctr = 0; int ctroctothorpe = 0; int numPin = 31; int capsPin = 30; int index = 0; void setup(){ //Selection of LCD begin characters lcd.begin(16,2); // set lcd in 16x2 characters //lcd.begin(20,4); // set lcd in 20x4 characters lcd.setCursor(0,0); // set the cursor in (0,0) /(COL,ROW) to begin lcd.print("LCD Shield"); // print a message to the LCD. //Serial.begin(9600); pinMode(numPin, OUTPUT); digitalWrite(numPin, LOW); pinMode(capsPin, OUTPUT); digitalWrite(capsPin, LOW); for (byte i=0;i<26;i++){ letters[i] = i+97; } keypad.addEventListener(keypadEvent); keypad.setHoldTime(500); } void loop(){ keypressed = keypad.getKey(); lcd.setCursor(0,1); if (keypressed) { // Serial.println(selchar); //Serial.println(stringBuff); lcd.print(stringBuff); } } /************************************************************/ /* Keypad Listener */ /************************************************************/ void keypadEvent(KeypadEvent key){ switch (keypad.getState()){ case PRESSED: if (!num){ pressTime = millis(); switch(key){ case '1': if(previous != '1') ctr=0; if(previous=='1'&&releaseTime-pressTime>4294966000){ index=index-1; }else{ ctr =0; } ctr++; if(ctr > 28) ctr=1; selchar = symbols[ctr-1]; break; case '2': if(previous != '2')ctr=0; if(previous=='2'&&releaseTime-pressTime>4294966000){ index=index-1; }else{ ctr =0; } ctr++; if(ctr > 3) ctr=1; selchar = letters[ctr-1]; break; case '3': if(previous != '3')ctr=3; if(previous=='3'&&releaseTime-pressTime>4294966000){ index=index-1; }else{ ctr =3; } ctr++; if(ctr > 6) ctr=4; selchar = letters[ctr-1]; break; case '4': if(previous != '4')ctr=6; if(previous=='4'&&releaseTime-pressTime>4294966000){ index=index-1; }else{ ctr =6; } ctr++; if(ctr > 9) ctr=7; selchar = letters[ctr-1]; break; case '5': if(previous != '5')ctr=9; if(previous=='5'&&releaseTime-pressTime>4294966000){ index=index-1; }else{ ctr =9; } ctr++; if(ctr > 12) ctr=10; selchar = letters[ctr-1]; break; case '6': if(previous != '6')ctr=12; if(previous=='6'&&releaseTime-pressTime>4294966000){ index=index-1; }else{ ctr =12; } ctr++; if(ctr > 15) ctr=13; selchar = letters[ctr-1]; break; case '7': if(previous != '7')ctr=15; if(previous=='7'&&releaseTime-pressTime>4294966000){ index=index-1; }else{ ctr =15; } ctr++; if(ctr > 19) ctr=16; selchar = letters[ctr-1]; break; case '8': if(previous != '8')ctr=19; if(previous=='8'&&releaseTime-pressTime>4294966000){ index=index-1; }else{ ctr =19; } ctr++; if(ctr > 22) ctr=20; selchar = letters[ctr-1]; break; case '9': if(previous != '9')ctr=22; if(previous=='9'&&releaseTime-pressTime>4294966000){ index=index-1; }else{ ctr =22; } ctr++; if(ctr > 26) ctr=23; selchar = letters[ctr-1]; break; case '0': selchar = symbols[28]; break; case '*': selchar = key; break; case '#': index=index-1; switch (caps){ case true: caps = false; for (byte i=0;i<26;i++){ letters[i] = i+97; } digitalWrite(capsPin,LOW); break; case false: caps = true; for (byte i=0;i<26;i++){ letters[i] = i+65; } digitalWrite(capsPin,HIGH); break; } break; } } else if(num){ selchar=key; } if(key =='A'){ // Backspace if (index <= 0) { index = 0; stringBuff[0]=' '; }else{ index--; stringBuff[index]=' '; } }else if(key == 'B'){ // Special Button Function. }else if(key == 'C'){ // Special Button Function. }else if(key == 'D'){ // Special Button Function. }else{ if(index > 19){ index = 0; for(int k=0;k<20;k++) stringBuff[k]=' '; } stringBuff[index]=selchar; index++; } break; case RELEASED: previous = key; releaseTime = millis(); break; case HOLD: if (key == '#') { if(num){ num = false; digitalWrite(numPin,LOW); }else{ num = true; digitalWrite(numPin,HIGH); } index=index-1; } break; } }