getting keypress output as linearity.

i want to get keypad press output linearity instead of line below line .

output like this { # # # # # # # # # }

instead of { #

}

#include <Keypad.h>


//40 ,39 ,38 , 37 .....................................

const byte ROWS = 5; 
const byte COLS = 4; 
char keys[ROWS][COLS] = {
  {'1','6','A','D'},
  {'2','7','B','E'},
  {'3','8','C','F'},
  {'4','9','X','Y'},
  {'5','0','Z','R'},
  
};
byte rowPins[ROWS] = {40,39,38,37,36}; //connect to row pinouts 
byte colPins[COLS] = {32,33,34,35}; //connect to column pinouts

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

void setup(){
  Serial.begin(9600);
}

void loop(){
  char key = keypad.getKey();

  if (key != NO_KEY){
    Serial.println(key);
  }
}

Change

Serial.println(key);

To

Serial.print(key);

The extra 'ln' makes a new line after it prints.

yes it is.
thanks.

any way it worked in linear thanks.
and
how can i limit the keypad presses into 10 .
like ending the press with 10 presses.

rajeetharan:
any way it worked in linear thanks.
and
how can i limit the keypad presses into 10 .
like ending the press with 10 presses.

Keep a variable that counts to 10. and only print if that counter is less than 10.

Many ways to accomplish this, add a counter somewhere every time there is a key press.

Example 1

int counter1 = 0;

void loop() {
  while (counter1 < 10)
    char key = keypad.getKey();

    if (key != NO_KEY){
      Serial.println(key);
      counter1++;
    }
  }
}

Example 2

int counter2 = 0;

void loop(){
  char key = keypad.getKey();

  if (key != NO_KEY){
    Serial.println(key);
    counter2++;
  }
  if (counter2 == 10) {
    while(1);
  }
}

Example 3
Same as Example 1, except put the loop inside setup() and have nothing inside loop()

Example 4 (what Arrch said)

int counter4 = 0;

void loop(){
  char key = keypad.getKey();

  if (key != NO_KEY){
    if (counter4 < 10) {
      Serial.println(key);
      counter4++;
  }
}

void loop()
:relaxed:

{
for(r=0;r<10;r++)
{
char key = keypad.getKey();

if (key != NO_KEY)
{
Serial.print(key);
}
}
}

I put the code inside code tags. The # button above the $) makes code tags.
You can quote-reply this post to see the code tags.

Does the keypad.getKey() function wait for a key to be pressed?
If not then that for loop will run in no time flat.
But you won’t notice at all. What you type will be echoed regardless.

You need to model more what you want to happen and how before coding.

void loop()
{
  for(r=0;r<10;r++)
   {
  char key = keypad.getKey();

     
  if (key != NO_KEY) 
  {
     Serial.print(key);
    } 
  }
}

Why are you using a for loop? You don't want to do a specific action 10 times; you want to keep track of when an action is done 10 times.

yes , when i tried it does 10 times one press.
so how can i drive it
through array

like char * key
??

rajeetharan:
yes , when i tried it does 10 times one press.
so how can i drive it
through array

like char * key
??

First, properly declare the array with enough space.

Then use the counting variable as the array index:

// upon keypress
keyArray[counter] = key;
counter++;

int key[10];
int p;
.........................

void loop()
{

key[p] = key;
i++;

char key = keypad.getKey();

if (key != NO_KEY)
{
Serial.print(key);

}
}

but error shows here key = key;

Edited my post to reflect the different variables names. Your array and single key input variable can't have the same name. Start using code tags, or I'm going to stop posting.

rajeetharan:
void loop()
:relaxed:

{
for(r=0;r<10;r++)
{
char key = keypad.getKey();

if (key != NO_KEY)
{
Serial.print(key);
}
}
}

Yeah that’s not going to work, the for loop will run, and then the loop() function will ‘loop’ itself again, and the for loop will start again (meaning it won’t stop after 10).

You name the int array 'key'. It is not good to name a char 'key' as well.
What is i? Where did you declare it?
It's a good thing that p doesn't increment because there's nothing to stop it from running past the end of key.

But don't fix those until you learn more how. You are not familiar with the code you try to write.

In your IDE click File->Examples->05 Control-> and go through all of those examples starting with Arrays. Then go do 02 Digital->BlinkWithoutDelay which tells how to deal with time on Arduino.

rajeetharan:

int key[10];

int p;

void loop()
{  
 
 key[p] = key;
  i++;
 
 char key = keypad.getKey();

if (key != NO_KEY)
 {
    Serial.print(key);
 
 }
}




but error shows here key *= key;*
*[/quote]*