KeyPad Counter Project Season 2

#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
#include <Keypad.h>
const int ROW_NUM = 4; //four rows
const int COLUMN_NUM = 4; //four columns
char keys[ROW_NUM][COLUMN_NUM] = {
  {'1', '2', '3', 'A'},
  {'4', '5', '6', 'B'},
  {'7', '8', '9', 'C'},
  {'*', '0', '#', 'D'}
};

int R1 = 1;
int C1 = 1;

int count;

byte pin_rows[ROW_NUM] = {A15, A14, A13, A12}; //connect to the row pinouts of the keypad
byte pin_column[COLUMN_NUM] = {A11, A10, A9, A8}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys), pin_rows, pin_column, ROW_NUM, COLUMN_NUM );

// #define Single_long_click_duration 10000

char Export[4];
byte a = 0;

void setup() {
  lcd.init(); // display initialization
  lcd.clear(); // clear the screen fully
  lcd.backlight(); // activate the backlight
  Export[0] = 0x0; // Set "Export" buffer string to an empty string
}

void loop()
{
  lcd.setCursor(C1, R1);
  char key = keypad.getKey();
  if (key)
  {
    switch(key)
    {

    case '0'...'9':
    if (C1 < 5) 
      {
       if (C1 < 4)
        {
          lcd.print(key);
          C1++;
          Export[a++]=key;
        }
      }
    break;

    case 'B':
    if(C1>1)
      {
        C1--;
        if (C1 < 1)
        C1 = 1;
        lcd.setCursor(C1, R1);
        lcd.print(' ');
     }
    break;

    case '#':
    lcd.setCursor(11, 1);
    lcd.print(Export);
    a=0;
    C1=1;
    lcd.setCursor(C1, R1);
    lcd.print("   ");

    count=Export;

    break;


    case 'C':
    count++;
    lcd.setCursor(11,1);
    lcd.print("   ");
    lcd.setCursor(11,1);
    lcd.print(count);
    break;
}
}

Here is one of the modified form of a project discussed earlier on this forum only

In above code :

The whole system is a kind of basic counter type system.
The observing area includes case '#': & case 'C': in the code

Here I use to enter a value up to 1 or 2 or 3 digits which gets printed on location (1,1) on LCD (as the dialed value)
and
After pressing key '#'
I get the same entered or dialed value result on the location (11,1)

Here the term Export(a++) is responsible for the complete function

A variable 'count' is defined as we can see in code before setup part . .
I use to make increments of count simply using key 'C' in case 'C': area

Now here comes the actual target :

I just want to equate the value of count with the 'Export[a]' value observed at (11,1)

Reason behind doing this is here :
I want to enter a random dialed single or double or triple digit number and want to start a count from that random dialed number in increasing order

For example =>

Say :
Enter a number '121'
and Enter (#) to display (11,1)
Then By pressing C it will count after '121' like :
122
123
124
125
126
and so on an on . . . . . Like that !!!!

or

Simply =>
Dial '11'
Enter (#)
Display(11,1)
Increment (C)
Result : 12 , 13 , 14 , 15 , so on . . .

Yeah I tried in Case '#' : but that is a complete disaster

Please Help Me getting the target !!!!!!!
Thanks

count is defind as an int, Export is a character array. count = Export makes no sense.

Yeah that is why i said its a complete disaster

Well

Then how to relate them in a way to get it equate ?

Please tell !!!!!!!

Make the code transforming the characters one by one.

Dint get the point ??
I mean in what way ??

Mmm No just numbers only not any text
All other A B C D ll be allotted some kind of function

Ya example 4 is for converting text to int

Oh yes but it's high time You manage bit, byte, char, int, long etc. It's very useful and important knowledge.

Ya Right !!

Any link or post from your side ??

Using Oncle Google on "converting ASCII to integer" this came up: convert ASCII to integer – Yahoo Sökresultat

Ya got this
Going through all the info !!!

Check the headlines for the most relevant section.

I see

Ok le me find out that way !!

Great reference site..

you're after count = atoi(Export);

good luck.. ~q

1 Like

Yes Yes that exactly I did and back here to inform and same result I got here with the post :blush:

Thanks !!!!!

Its working . .

1 Like

So here is the final code from all the reference links and sources you all provide and guide me
:blush:
Thanks to all

#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
#include <Keypad.h>
const int ROW_NUM = 4; //four rows
const int COLUMN_NUM = 4; //four columns
char keys[ROW_NUM][COLUMN_NUM] = {
  {'1', '2', '3', 'A'},
  {'4', '5', '6', 'B'},
  {'7', '8', '9', 'C'},
  {'*', '0', '#', 'D'}
};

int R1 = 1;
int C1 = 1;

int count;

byte pin_rows[ROW_NUM] = {A15, A14, A13, A12}; //connect to the row pinouts of the keypad
byte pin_column[COLUMN_NUM] = {A11, A10, A9, A8}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys), pin_rows, pin_column, ROW_NUM, COLUMN_NUM );

// #define Single_long_click_duration 10000

const byte numChars = 32;
char receivedChars[numChars];   // an array to store the received data

boolean newData = false;

int dataNumber = 0;             // new for this version

char Export[4];
byte a = 0;

void setup() {
  lcd.init(); // display initialization
  lcd.clear(); // clear the screen fully
  lcd.backlight(); // activate the backlight
  // Export[0] = 0x0; // Set "Export" buffer string to an empty string
}

void loop()
{
  lcd.setCursor(C1, R1);
  char key = keypad.getKey();
  if (key)
  {
    switch(key)
    {

    case '0'...'9':
    if (C1 < 4) 
      {
          Export[a++] = key;
          Export[a] = 0x0;
          if (atoi(Export) > 444) 
          {
            Export[--a] = 0x0;
            break;
          }
          lcd.print(key);
          C1++;
          // count = atoi(Export);
      }
        break;

    case 'B':
    if(C1>1)
      {
        C1--;
        if (C1 < 1)
        C1 = 1;
        Export[--a] = 0x0;
        count = atoi(Export);
        lcd.setCursor(C1, R1);
        lcd.print(' ');
      }
      break;

    case '#':
    lcd.setCursor(11, 1);
    lcd.print("   ");
    lcd.setCursor(11, 1);
    lcd.print(Export);
    count = atoi(Export); //Converting 'chart to int' VIP
    a=0;
    C1=1;
    lcd.setCursor(C1, R1);
    lcd.print("   ");
    
    break;


    case 'C':
    if(count<444)
    {
    count=count+1;
    }
    else
    {
    count=1;
    }
    lcd.setCursor(11,1);
    lcd.print("   ");
    lcd.setCursor(11,1);
    lcd.print(count);
    break;
    

    case 'D':
    if(count>1)
    {
    count=count-1;
    }
    else
    {
    count=444;
    }
    lcd.setCursor(11,1);
    lcd.print("   ");
    lcd.setCursor(11,1);
    lcd.print(count);
    break;


    } //end switch for HOLD

    } // end switch for keystate

  }

With this key 'B'
I need to press one by one to erase data

so Including this function
Is there any option that if I use to press key 'B' for more than a couple of second
The whole entered data would get erased at a time ??

Long press of key to function !!!

Great job!!

long press possible but complicated and you still have A and * not being used..
use * or A for an all clear and still can use the left over for another function you're bound to dream up.. :slight_smile:

have fun.. ~q

Thanks :blush:

Yeah that is already I did with this one

case '*': // Clear all
        lcd.setCursor(1, 1);
        lcd.print("   ");
        C1 = 1;
        a = 0;
        count = 0;
        break;

While doing this code , the idea of long pressed hit my mind

and I planned to dive deep inside the 4x4 so as to learn more and more
to the core level :slight_smile:

1 Like

check here..
Keypad.h
when i work an issue, first thing i usually do is find the *.h file..

i see keypad has a public member isPressed(char keyChar);
you'll be using it to get your long press..

maybe at top of loop..
pseudo code..
if ispressed(thekey)
howlong =millis()
while ispressed(thekey)
check millis for how long long press last..
longpress=true
break out of while loop..

sounds like an episode for season 3.. :slight_smile:

have fun.. ~q

Yeah a bit complex one :grimacing: :grimacing: :grimacing: :grimacing:

Enough to engage time for 4 to 7 simple topics

I am about to launch season 3 for this keypad

There I am about to include extra inputs outputs for assigning various functions

:blush: