Print from Keypad to Serial Monitor (to start)

Hi Guys
I am trying to take 2 values from a keypad and initially print them to the serial monitor. at the min i can print values singly. How can i store these values from the user and then print them with my temp.???
all and any help is appreciated

#include <Keypad.h>
#include <stdio.h>
#include <string.h>

const byte numRows= 4; //number of rows on the keypad
const byte numCols= 4; //number of columns on the keypad

//keymap defines the key pressed according to the row and columns just as appears on the keypad
char keymap[numRows][numCols]=
{
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};

//Code that shows the the keypad connections to the arduino terminals
byte rowPins[numRows] = {9,8,7,6}; //Rows 0 to 3
byte colPins[numCols]= {5,4,3,2}; //Columns 0 to 3

//initializes an instance of the Keypad class
Keypad myKeypad= Keypad(makeKeymap(keymap), rowPins, colPins, numRows, numCols);

char entryStr[3];
int i=0;

void setup()
{
Serial.begin(9600);
Serial.println("Min Temp = Max Temp = ");
}

void loop()
{

char keypressed = myKeypad.getKey();

if (keypressed == 'D')
{
GetMinMax();
}

}

float GetMinMax()
{
//int Num[1];
//int i = 0;
char str[3];
char keypressed = myKeypad.getKey();

i=0;
keypressed=0;

entryStr*= keypressed;*

  • i++;*

  • Serial.print(keypressed);*

  • Serial.println("Please Enter your new Min Temp");*

  • char key = myKeypad.getKey();*

  • while(key == NO_KEY)*

  • {*

  • key = myKeypad.getKey(); //UPDATE VALUE*

  • //Serial.println("Waiting for press"); //This will print as long as no keys are pressed*

  • }*

  • Serial.println(key);*

  • Serial.println("Please Enter your next number");*

  • char keypressed1 = myKeypad.getKey();*

  • char key1 = myKeypad.getKey();*

  • while(key1 == NO_KEY)*

  • {*

  • key1 = myKeypad.getKey(); //UPDATE VALUE*

  • }*

  • Serial.println(key1);*

  • Serial.println("MIN TEMP = ",(key) );*
    Serial.println("Please Enter your new Max Temp");

  • char keypressed2 = myKeypad.getKey();*

  • char key2 = myKeypad.getKey();*

  • while(key2 == NO_KEY)*

  • {*

  • key2 = myKeypad.getKey(); //UPDATE VALUE*

  • }*

  • Serial.println(key2);*

  • Serial.println("Please Enter your next number");*

  • char keypressed3 = myKeypad.getKey();*

  • char key3 = myKeypad.getKey();*

  • while(key3 == NO_KEY)*

  • {*

  • key3 = myKeypad.getKey(); //UPDATE VALUE*

  • }*

  • Serial.println(key3);*

  • Serial.println("MAX TEMP = ");*

  • }*

Welcome to the forum

Start by reading How to use this forum and post your code using code tags after formatting it in the IDE using Auto format

Using code tags will prevent it being turned into italics and make the code easier to copy for testing

#include <Keypad.h>
#include <stdio.h>
#include <string.h>





const byte numRows= 4; //number of rows on the keypad
const byte numCols= 4; //number of columns on the keypad

//keymap defines the key pressed according to the row and columns just as appears on the keypad
char keymap[numRows][numCols]=
{
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};

//Code that shows the the keypad connections to the arduino terminals
byte rowPins[numRows] = {9,8,7,6}; //Rows 0 to 3
byte colPins[numCols]= {5,4,3,2}; //Columns 0 to 3

//initializes an instance of the Keypad class
Keypad myKeypad= Keypad(makeKeymap(keymap), rowPins, colPins, numRows, numCols);

char entryStr[3];
int i=0;

void setup()
{
Serial.begin(9600);
Serial.println("Min Temp =     Max Temp =   ");
}


void loop()
{
 
  char keypressed = myKeypad.getKey();
 
  if (keypressed == 'D')
  {
    GetMinMax();
  }


     
    }


float GetMinMax()
{
  //int Num[1];
  //int i = 0;
  char str[3];
   char keypressed = myKeypad.getKey();
 

   i=0;
   keypressed=0;
 
     entryStr= keypressed;
     i++;
     Serial.print(keypressed);


 
  Serial.println("Please Enter your new Min Temp");

 
  char key = myKeypad.getKey();
  while(key == NO_KEY)
    {
       key = myKeypad.getKey(); //UPDATE VALUE
     
      //Serial.println("Waiting for press"); //This will print as long as no keys are pressed
   
    }
   
    Serial.println(key);
    Serial.println("Please Enter your next number");

    char keypressed1 = myKeypad.getKey();
  char key1 = myKeypad.getKey();
  while(key1 == NO_KEY)
    {
       key1 = myKeypad.getKey(); //UPDATE VALUE
    }
    Serial.println(key1);
    Serial.println("MIN TEMP = ",(key) );


Serial.println("Please Enter your new Max Temp");

  char keypressed2 = myKeypad.getKey();
  char key2 = myKeypad.getKey();
  while(key2 == NO_KEY)
    {
       key2 = myKeypad.getKey(); //UPDATE VALUE
     
    }
   
    Serial.println(key2);
    Serial.println("Please Enter your next number");

    char keypressed3 = myKeypad.getKey();
    char key3 = myKeypad.getKey();
    while(key3 == NO_KEY)
    {
       key3 = myKeypad.getKey(); //UPDATE VALUE
    }
    Serial.println(key3);
   
    Serial.println("MAX TEMP =  ");

   }[code][code]

[/code][/code]

is this the correct format UKHeliBob ?

Much better except for the extra pair of code tags at the end of the code

OK. Let's start with a basic problem with the code as posted

entryStr = keypressed;

Is that how your code looks in the IDE or is it actually

entryStr[i] = keypressed;

Did you copy the code from your original post or from the IDE when posting it in code tags ?

I copied it from the original post, I will copy from the IDE if that helps?

pie_man:
I copied it from the original post, I will copy from the IDE if that helps?

The code in your original post was mangled because the forum software interprets [­i] as a command to change the following text to italics and it makes the "command" invisible

Post the code from your IDE in code tags to avoid this problem

#include <Keypad.h>
#include <stdio.h>
#include <string.h>

const byte numRows= 4; //number of rows on the keypad
const byte numCols= 4; //number of columns on the keypad

//keymap defines the key pressed according to the row and columns just as appears on the keypad
char keymap[numRows][numCols]=
{
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};

//Code that shows the the keypad connections to the arduino terminals
byte rowPins[numRows] = {9,8,7,6}; //Rows 0 to 3
byte colPins[numCols]= {5,4,3,2}; //Columns 0 to 3

//initializes an instance of the Keypad class
Keypad myKeypad= Keypad(makeKeymap(keymap), rowPins, colPins, numRows, numCols);

char entryStr[3];
int i=0;

void setup()
{
Serial.begin(9600);
Serial.println("Min Temp = Max Temp = Press D to Enter New Temperature");
}

void loop()
{

char keypressed = myKeypad.getKey();

if (keypressed == 'D')
{
GetMinMax();
}

}

float GetMinMax()
{
int Num[1];
int i = 0;
char str[3];
char keypressed = myKeypad.getKey();

i=0;
keypressed=0;

entryStr*= keypressed;*

  • i++;*

  • Serial.print(keypressed);*

  • Serial.println("Please Enter your new Min Temp");*

  • { for(i =0; i<1; i++)*

  • {*

  • char A = myKeypad.getKey();*

  • Serial.print(A);*
    _ Num*= A;*_

_ Serial.print(Num*);
}
char key = myKeypad.getKey();_
while(key == NO_KEY)
_ {
key = myKeypad.getKey(); //UPDATE VALUE*_

* //Serial.println("Waiting for press"); //This will print as long as no keys are pressed*

* }*

* Serial.println(key);*

* Serial.println("Please Enter your next number");*
* { for(i =0; i<1; i++)*
* {*
* char A = myKeypad.getKey();*
* Serial.print(A);*
_ Num*= A;*_

_ Serial.print(Num*);
}
char keypressed1 = myKeypad.getKey();
char key1 = myKeypad.getKey();_

while(key1 == NO_KEY)
_ {
key1 = myKeypad.getKey(); //UPDATE VALUE*

* }
Serial.println(key1);
Serial.println("MIN TEMP = " );
Serial.println("Please Enter your new Max Temp");
char keypressed2 = myKeypad.getKey();
char key2 = myKeypad.getKey();_

while(key2 == NO_KEY)
_ {
key2 = myKeypad.getKey(); //UPDATE VALUE*_

* }*

* Serial.println(key2);*
* Serial.println("Please Enter your next number");*
* char keypressed3 = myKeypad.getKey();*
* char key3 = myKeypad.getKey();*
* while(key3 == NO_KEY)
_ {
key3 = myKeypad.getKey(); //UPDATE VALUE*

* }
Serial.println(key3);*_

* Serial.println("MAX TEMP = ");*
* } } }*

#include <Keypad.h>
#include <stdio.h>
#include <string.h>





const byte numRows= 4; //number of rows on the keypad
const byte numCols= 4; //number of columns on the keypad

//keymap defines the key pressed according to the row and columns just as appears on the keypad
char keymap[numRows][numCols]=
{
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};

//Code that shows the the keypad connections to the arduino terminals
byte rowPins[numRows] = {9,8,7,6}; //Rows 0 to 3
byte colPins[numCols]= {5,4,3,2}; //Columns 0 to 3

//initializes an instance of the Keypad class
Keypad myKeypad= Keypad(makeKeymap(keymap), rowPins, colPins, numRows, numCols);

char entryStr[3];
int i=0;

void setup()
{
Serial.begin(9600);
Serial.println("Min Temp =     Max Temp =      Press  D to Enter New Temperature");
}


void loop()
{
 
  char keypressed = myKeypad.getKey();
  
  if (keypressed == 'D')
  {
    GetMinMax();
  }


     
    }


float GetMinMax()
{
  int Num[1];
  int i = 0;
  char str[3];
   char keypressed = myKeypad.getKey();
  

   i=0;
   keypressed=0;
 
     entryStr[i]= keypressed;
     i++;
     Serial.print(keypressed);


  
  Serial.println("Please Enter your new Min Temp");
  { for(i =0; i<1; i++)
       {
         char A = myKeypad.getKey();
         Serial.print(A);
         Num[i]= A;
         
      Serial.print(Num[i]);
      }   
 
  char key = myKeypad.getKey();
  while(key == NO_KEY)
    {
       key = myKeypad.getKey(); //UPDATE VALUE
      
      //Serial.println("Waiting for press"); //This will print as long as no keys are pressed
    
    }
   
    Serial.println(key);
  
    Serial.println("Please Enter your next number");
    { for(i =0; i<1; i++)
       {
         char A = myKeypad.getKey();
         Serial.print(A);
         Num[i]= A;
         
      Serial.print(Num[i]);
      }   

    char keypressed1 = myKeypad.getKey();
  char key1 = myKeypad.getKey();
  while(key1 == NO_KEY)
    {
       key1 = myKeypad.getKey(); //UPDATE VALUE
    }
    Serial.println(key1);
    Serial.println("MIN TEMP = " );


Serial.println("Please Enter your new Max Temp");

  char keypressed2 = myKeypad.getKey();
  char key2 = myKeypad.getKey();
  while(key2 == NO_KEY)
    {
       key2 = myKeypad.getKey(); //UPDATE VALUE
     
    }
   
    Serial.println(key2);
    Serial.println("Please Enter your next number");

    char keypressed3 = myKeypad.getKey();
    char key3 = myKeypad.getKey();
    while(key3 == NO_KEY)
    {
       key3 = myKeypad.getKey(); //UPDATE VALUE
    }
    Serial.println(key3);
    
    Serial.println("MAX TEMP =  ");

    }  }   }

pie_man:
#include <Keypad.h>
#include <stdio.h>
#include <string.h>

const byte numRows= 4; //number of rows on the keypad
const byte numCols= 4; //number of columns on the keypad

//keymap defines the key pressed according to the row and columns just as appears on the keypad
char keymap[numRows][numCols]=
{
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};

//Code that shows the the keypad connections to the arduino terminals
byte rowPins[numRows] = {9,8,7,6}; //Rows 0 to 3
byte colPins[numCols]= {5,4,3,2}; //Columns 0 to 3

//initializes an instance of the Keypad class
Keypad myKeypad= Keypad(makeKeymap(keymap), rowPins, colPins, numRows, numCols);

char entryStr[3];
int i=0;

void setup()
{
Serial.begin(9600);
Serial.println("Min Temp = Max Temp = Press D to Enter New Temperature");
}

void loop()
{

char keypressed = myKeypad.getKey();

if (keypressed == 'D')
{
GetMinMax();
}

}

float GetMinMax()
{
int Num[1];
int i = 0;
char str[3];
char keypressed = myKeypad.getKey();

i=0;
keypressed=0;

entryStr*= keypressed;*

  • i++;*
  • Serial.print(keypressed);*

Serial.println("Please Enter your new Min Temp");
{ for(i =0; i<1; i++)

  • {*
  • char A = myKeypad.getKey();*
  • Serial.print(A);*
    _ Num*= A;*_

_ Serial.print(Num*);
}
char key = myKeypad.getKey();
while(key == NO_KEY)
{
key = myKeypad.getKey(); //UPDATE VALUE*_

* //Serial.println("Waiting for press"); //This will print as long as no keys are pressed*

* }*

* Serial.println(key);*

* Serial.println("Please Enter your next number");*
* { for(i =0; i<1; i++)*
* {*
* char A = myKeypad.getKey();*
* Serial.print(A);*
_ Num*= A;*_

_ Serial.print(Num*);
}
char keypressed1 = myKeypad.getKey();
char key1 = myKeypad.getKey();
while(key1 == NO_KEY)
{
key1 = myKeypad.getKey(); //UPDATE VALUE*

* }
Serial.println(key1);
Serial.println("MIN TEMP = " );
Serial.println("Please Enter your new Max Temp");
char keypressed2 = myKeypad.getKey();
char key2 = myKeypad.getKey();
while(key2 == NO_KEY)
{
key2 = myKeypad.getKey(); //UPDATE VALUE*_

* }*

* Serial.println(key2);*
* Serial.println("Please Enter your next number");*
* char keypressed3 = myKeypad.getKey();*
* char key3 = myKeypad.getKey();*
* while(key3 == NO_KEY)
_ {
key3 = myKeypad.getKey(); //UPDATE VALUE*

* }
Serial.println(key3);*_

* Serial.println("MAX TEMP = ");*
* } } }*
[/quote]

What's the point of a one element array?

TheMemberFormerlyKnownAsAWOL:
What's the point of a one element array?

Luckily it is only being used with a one step for loop

    for (i = 0; i < 1; i++)
    {
      char A = myKeypad.getKey();
      Serial.print(A);
      Num[i] = A;
      Serial.print(Num[i]);
    }

But still of no use

pie_man - can you please explain what you want that for loop to do ?

TheMemberFormerlyKnownAsAWOL:
What's the point of a one element array?

Future expansion?

I want to take two values from the user(keypad entry), then use those two values to display a new lower limit i.e. New min temp = value 1 , value 2

any thoughts guys, apologies as I am very new to this

Are the 2 values entered by the user only going to be between 0 and 9 ?

UKHeliBob:
Are the 2 values entered by the user only going to be between 0 and 9 ?

I was about to ask that exact question... if not, needs to have a function to take >1 digit as an integer.

Is there a "standard" library that does that? I have not seen that facility in keypad.h, so I rolled my own.

Is there a "standard" library that does that?

It is certainly not part of the Keypad library but as you know it is not difficult to implement such functionality

yes UKHeliBob

pie_man:
yes UKHeliBob

What question are you answering ?

it has to enter a number between 1 and 9