Looking for a correct T9

Hi guys. I'm looking for a correct T9 for 4 X 4 Membrane Keypad. It looks like 2 codes i found aren't correct. I tried to fix but diffrence is too much to fix. I know as on T9 keyboards, we click one time to just put number, 2 times to print first char, 3 times to print second and 4 times to print 3st char, after 1000ms char will printed. But in these codes. I cant do that because when i want to type 'C', it will print "ABC". does somewone can give me an example (Library = Keypad.h)

I've an old code hack for a 4x3 that could be a start

it's easy to add a column, just declare the keypad correctly and add rows to the the t9Map for your new keys and what they will cycle through and because I hardwired finding the right entry, you'll need to modify the places where I do the mapping

        if (currentKey == '#')      currentMap = &t9Map[11];
        else if (currentKey == '*') currentMap = &t9Map[10];
        else currentMap = &t9Map[currentKey - '0'];

to include you own mapping for other keys as currentKey - '0' will only work for digits


#include <Keypad.h>

const uint8_t ROWS = 4;
const uint8_t COLS = 3;
char keys[ROWS][COLS] = {
  { '1', '2', '3'},
  { '4', '5', '6'},
  { '7', '8', '9'},
  { '*', '0', '#'}
};

uint8_t colPins[COLS] = {4, 3, 2};
uint8_t rowPins[ROWS] = {8, 7, 6, 5};

Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);

struct Description {
  char key;
  const char * choices;
};

Description t9Map[] = {
  {'0', "0"},
  {'1', "1"},
  {'2', "ABC2"},
  {'3', "DEF3"},
  {'4', "GHI4"},
  {'5', "JKL5"},
  {'6', "MNO6"},
  {'7', "PQRS7"},
  {'8', "TUV8"},
  {'9', "WXYZ9"},
  {'*', "*"},
  {'#', "#"},
};

enum : byte {WAITING, KEYPRESS} state = WAITING;

char getKey() {
  static byte currentKeyIndex = 0;
  static Description* currentMap = nullptr;
  char currentKey = keypad.getKey();
  static uint32_t t0;
  char finalKey = NO_KEY;

  switch (state) {
    case WAITING:
      if (currentKey != NO_KEY) {
        t0 = millis();
        currentKeyIndex = 0;
        state = KEYPRESS;

        if (currentKey == '#')      currentMap = &t9Map[11];
        else if (currentKey == '*') currentMap = &t9Map[10];
        else currentMap = &t9Map[currentKey - '0'];
        Serial.write('(');
        Serial.write(currentMap->choices[currentKeyIndex]);
        Serial.write(')');
      }
      break;

    case KEYPRESS:
      if (currentKey != NO_KEY) {
        if (currentKey == currentMap->key) {
          // same key again, get next representation
          t0 = millis();
          if (++currentKeyIndex >= strlen(currentMap->choices)) currentKeyIndex = 0;
          Serial.write('(');
          Serial.write(currentMap->choices[currentKeyIndex]);
          Serial.write(')');
        } else {
          // new key, validate the previous one and be ready for that one
          finalKey = currentMap->choices[currentKeyIndex];
          Serial.write('[');
          Serial.write(finalKey);
          Serial.write(']');
          t0 = millis();
          currentKeyIndex = 0;
          if (currentKey == '#')      currentMap = &t9Map[11];
          else if (currentKey == '*') currentMap = &t9Map[10];
          else currentMap = &t9Map[currentKey - '0'];
          Serial.write('(');
          Serial.write(currentMap->choices[currentKeyIndex]);
          Serial.write(')');
        }
      }
      else if (millis() - t0 >= 1000) {
        finalKey = currentMap->choices[currentKeyIndex];
        state = WAITING;
      }
      break;
  }

  return finalKey;
}

void setup() {
  Serial.begin(115200);
  Serial.println("Ready");
}

void loop() {
  char k = getKey();
  if (k != NO_KEY) {
    Serial.print(F("\nGot : "));
    Serial.println(k);
  }
}

actually ill maybe use ABCD buttons just for send '\n' buttons

i cant send new line with it

Show us what you tried

just assigned '\n' to 'A' on the char map (i also make the code compatible with 4x4)

Post the code…

do you know i have to switch between my forum and programming laptop PCs?

I don’t get your point…
Bye.

wait i used the usb

S E C R E T C O D E
#include <Keypad.h>

const uint8_t ROWS = 4;
const uint8_t COLS = 4;
char keys[ROWS][COLS] = {
  { '1', '2', '3', 'A'},
  { '4', '5', '6', 'B'},
  { '7', '8', '9', 'C'},
  { '*', '0', '#', 'D'}
};

uint8_t colPins[COLS] = {3,4,5,6};
uint8_t rowPins[ROWS] = {7,8,9,10};

Keypad keypad = Keypad(makeKeymap(keys), colPins, rowPins, ROWS, COLS);

struct Description {
  char key;
  const char * choices;
};

Description t9Map[] = {
  {'0', "0"},
  {'1', "1"},
  {'2', "ABC2"},
  {'3', "DEF3"},
  {'4', "GHI4"},
  {'5', "JKL5"},
  {'6', "MNO6"},
  {'7', "PQRS7"},
  {'8', "TUV8"},
  {'9', "WXYZ9"},
  {'*', "*"},
  {'#', "#"},
  {'A', '\n'},
  {'B', " "},
  {'C', "?"},
};

enum : byte {WAITING, KEYPRESS} state = WAITING;

char getKey() {
  static byte currentKeyIndex = 0;
  static Description* currentMap = nullptr;
  char currentKey = keypad.getKey();
  static uint32_t t0;
  char finalKey = NO_KEY;

  switch (state) {
    case WAITING:
      if (currentKey != NO_KEY) {
        t0 = millis();
        currentKeyIndex = 0;
        state = KEYPRESS;

        if (currentKey == '#')      currentMap = &t9Map[11];
        else if (currentKey == '*') currentMap = &t9Map[10];
        else currentMap = &t9Map[currentKey - '0'];
        //Serial.write('(');
        //Serial.write(currentMap->choices[currentKeyIndex]);
        //Serial.write(')');
      }
      break;

    case KEYPRESS:
      if (currentKey != NO_KEY) {
        if (currentKey == currentMap->key) {
          // same key again, get next representation
          t0 = millis();
          if (++currentKeyIndex >= strlen(currentMap->choices)) currentKeyIndex = 0;
          //Serial.write('(');
          //Serial.write(currentMap->choices[currentKeyIndex]);
          //Serial.write(')');
        } else {
          // new key, validate the previous one and be ready for that one
          finalKey = currentMap->choices[currentKeyIndex];
          //Serial.write('[');
          //Serial.write(finalKey);
          //Serial.write(']');
          t0 = millis();
          currentKeyIndex = 0;
          if (currentKey == '#')      currentMap = &t9Map[11];
          else if (currentKey == '*') currentMap = &t9Map[10];
          else currentMap = &t9Map[currentKey - '0'];
          //Serial.write('(');
          //Serial.write(currentMap->choices[currentKeyIndex]);
          //Serial.write(')');
        }
      }
      else if (millis() - t0 >= 1000) {
        finalKey = currentMap->choices[currentKeyIndex];
        state = WAITING;
      }
      break;
  }

  return finalKey;
}

void setup() {
  Serial.begin(9600);
  //Serial.println("Ready");
}

void loop() {
  char k = getKey();
  if (k != NO_KEY) {
    
    Serial.print(k);
  }
}

Jackson wait i post the code !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

You missed that

Compare the description field with all the other description fields that you have; this throws a warning on AVR based boards and probably an error on other boards.

that gived nothing on compiler or Serial

Show us how you fixed both comments (posts 13 and 14)

i actually dont understand why you need if when its already exists on array

If that was regarding my comment about the '\n', I suggest that you set the warning level in file → preferences in the IDE to ALL.

I accidently found that "." is a \0

I give up