Hello to you all !
i have an Arduino Mega 2560 with a 2x16 cld screen and a 4x4 keypad, every thing is ok connected and i runned the dynamickepad example and everything worked just fine.
i am trying to create a text string that i can add or dellete 32 characters from it and eventualy i can print the string to the lcd.
so i messed up with the example, add something here, dellete something there but i can not find a way to make it work.
i am sure that it not the most efficient code, so any suggestion is more than welcome.
Here is the code :
#include <Keypad.h>
#include <LiquidCrystal.h>
const byte ROWS = 4; //four rows
const byte COLS = 4; //three columns
// Define the keymaps. The blank spot (lower left) is the space character.
char alphaKeys[ROWS][COLS] = {
{ 'a','d','g','A' },
{ 'j','m','p','B' },
{ 's','v','y','C' },
{ ' ','.','#','D' }
};
char numberKeys[ROWS][COLS] = {
{ '1','2','3','A' },
{ '4','5','6','B' },
{ '7','8','9','C' },
{ ' ','0','#','D' }
};
boolean alpha = false; // Start with the numeric keypad.
char* keypadMap = (alpha == true) ? makeKeymap(alphaKeys) : makeKeymap(numberKeys);
byte rowPins[ROWS] = {48, 49, 50, 51}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {40, 41, 43, 42}; //connect to the column pinouts of the keypad
//create a new Keypad
Keypad keypad = Keypad(keypadMap, rowPins, colPins, sizeof(rowPins), sizeof(colPins));
unsigned long startTime;
const byte ledPin = 13; // Use the LED on pin 13.
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
char* myStrings[32];
int i;
void setup(){
lcd.begin(16, 2);
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW); // Turns the LED on.
keypad.addEventListener(keypadEvent); // Add an event listener.
keypad.setHoldTime(500);
}
void loop(){
char key = keypad.getKey();
if (alpha && millis()-startTime>100) { // Flash the LED if we are using the letter keymap.
digitalWrite(ledPin,!digitalRead(ledPin));
startTime = millis();
}
}
void keypadEvent(KeypadEvent key) {
static char virtKey = NO_KEY; // Stores the last virtual key press. (Alpha keys only)
static char physKey = NO_KEY; // Stores the last physical key press. (Alpha keys only)
static char buildStr[12];
static byte buildCount;
static byte pressCount;
switch (keypad.getState())
{
case PRESSED:
if (isalpha(key)) { // This is a letter key so we're using the letter keymap.
if (physKey != key) { // New key so start with the first of 3 characters.
pressCount = 0;
virtKey = key;
physKey = key;
myStrings[i] = key;
}
else { // Pressed the same key again...
virtKey++; // so select the next character on that key.
pressCount++; // Tracks how many times we press the same key.
myStrings++;
}
if (pressCount > 2) { // Last character reached so cycle back to start.
pressCount = 0;
virtKey = key;
}
lcd.print(myStrings); // Used for testing.
}
if (isdigit(key) || key == ' ' || key == '.') lcd.print(myStrings);
if (key == '#') lcd.println();
break;
case HOLD:
if (key == '#') { // Toggle between keymaps.
if (alpha == true) { // We are currently using a keymap with letters
keypad.begin(*numberKeys); // and want to change to numbers.
alpha = false;
digitalWrite(ledPin, LOW);
}
else { // Or, we are currently using a keymap with numbers
keypad.begin(*alphaKeys); // and want to change to letters.
alpha = true;
}
}
else { // Some key other than '#' was pressed.
buildStr[buildCount++] = (isalpha(key)) ? virtKey : key;
buildStr[buildCount] = '\0';
lcd.println();
lcd.println(buildStr);
}
break;
case RELEASED:
if (buildCount >= sizeof(buildStr)) buildCount = 0; // Our string is full. Start fresh.
break;
} // end switch-case
} // end keypad events
Moderator: CODE TAGS.
AND THIS IS THE COMPILER RESULT :
sketch_feb09b.cpp: In function 'void keypadEvent(KeypadEvent)':
sketch_feb09b:68: error: invalid conversion from 'KeypadEvent' to 'char*'
sketch_feb09b:73: error: lvalue required as increment operand
sketch_feb09b:79: error: call of overloaded 'print(char* [32])' is ambiguous
C:\Users\sakis\Desktop\arduino-1.0\hardware\arduino\cores\arduino/Print.h:55: note: candidates are: size_t Print::print(char)
C:\Users\sakis\Desktop\arduino-1.0\hardware\arduino\cores\arduino/Print.h:56: note: size_t Print::print(unsigned char, int)
C:\Users\sakis\Desktop\arduino-1.0\hardware\arduino\cores\arduino/Print.h:57: note: size_t Print::print(int, int)
C:\Users\sakis\Desktop\arduino-1.0\hardware\arduino\cores\arduino/Print.h:58: note: size_t Print::print(unsigned int, int)
C:\Users\sakis\Desktop\arduino-1.0\hardware\arduino\cores\arduino/Print.h:59: note: size_t Print::print(long int, int)
C:\Users\sakis\Desktop\arduino-1.0\hardware\arduino\cores\arduino/Print.h:60: note: size_t Print::print(long unsigned int, int)
sketch_feb09b:81: error: call of overloaded 'print(char* [32])' is ambiguous
C:\Users\sakis\Desktop\arduino-1.0\hardware\arduino\cores\arduino/Print.h:55: note: candidates are: size_t Print::print(char)
C:\Users\sakis\Desktop\arduino-1.0\hardware\arduino\cores\arduino/Print.h:56: note: size_t Print::print(unsigned char, int)
C:\Users\sakis\Desktop\arduino-1.0\hardware\arduino\cores\arduino/Print.h:57: note: size_t Print::print(int, int)
C:\Users\sakis\Desktop\arduino-1.0\hardware\arduino\cores\arduino/Print.h:58: note: size_t Print::print(unsigned int, int)
C:\Users\sakis\Desktop\arduino-1.0\hardware\arduino\cores\arduino/Print.h:59: note: size_t Print::print(long int, int)
C:\Users\sakis\Desktop\arduino-1.0\hardware\arduino\cores\arduino/Print.h:60: note: size_t Print::print(long unsigned int, int)
I have no idea what to do ! PLZ HELP !