keypad code poblem

Hi everyone,
i would really appreciate any suggestions
i am trying to get from the user three variables
he will enter it by keypad and it will show in the lcd
the problem is when he enters the first variable as 3 and the second as 5
it shows as if the second is 35 and not 5
i am looking for a code that will restart the keypad and clear the first value entered

Show us the code you have so far, we might be able to spot the cause of your issue.

Supply your code.

Please put your code in its own window as seen in other posts. This can be done by placing

[code]and [/code]

around the code. This makes it easier for others to read.

Weedpharma

this is the code i am trying to make a traffic light but i need the user to enter the time of each colour

int pinled1 = 8;
int pinled2 = 9;
int pinled3 = 10;
int pinled4 = 18;
int pinled5 = 19;
char Redtime[4];
char Yellowtime[4];
char Greentime[4];

#include <Keypad.h>
const byte ROWS = 4;
const byte COLS = 3;
char keys[ROWS][COLS] = {
{‘1’,‘2’,‘3’},
{‘4’,‘5’,‘6’},
{‘7’,‘8’,‘9’},
{’*’,‘0’,’#’},
};
byte rowPins[ROWS] = {17, 16, 15, 14}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {13, 12, 11}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

#include <LiquidCrystal.h>
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);

void setup(){
Serial.begin(9600);
lcd.begin(16,2);
lcd.clear();
lcd.setCursor(0,0);
lcd.print(“Enter Redtime:”);
Redtime[0] = ‘0’;
Redtime[1] = ‘0’;
Redtime[2] = ‘0’;
Redtime[3] = ‘0’;
lcd.setCursor(0,1);
lcd.print(Redtime[0]);
lcd.print(Redtime[1]);
lcd.print(Redtime[2]);
lcd.print(Redtime[3]);
pinMode (pinled1, OUTPUT );
pinMode (pinled2, OUTPUT );
pinMode (pinled3, OUTPUT );
pinMode (pinled4, OUTPUT );
pinMode (pinled5, OUTPUT );
digitalWrite(pinled1, LOW);
digitalWrite(pinled2, LOW);
digitalWrite(pinled3, LOW);
digitalWrite(pinled4, LOW);
digitalWrite(pinled5, LOW);
}

void loop(){
char key = keypad.getKey();
lcd.setCursor(0,0);
if (key != NO_KEY )
{if (key != ‘#’)
{Redtime[0] = Redtime[1];
Redtime[1] = Redtime[2];
Redtime[2] = Redtime[3];
Redtime[3] = key;
lcd.setCursor(0,1);
lcd.print(Redtime[0]);
lcd.print(Redtime[1]);
lcd.print(Redtime[2]);
lcd.print(Redtime[3]);}
else
{lcd.clear();
lcd.setCursor(0,0);
lcd.print(“Enter Yellowtime”);
Yellowtime[0] = ‘0’;
Yellowtime[1] = ‘0’;
Yellowtime[2] = ‘0’;
Yellowtime[3] = ‘0’;
lcd.setCursor(0,1);
lcd.print(Yellowtime[0]);
lcd.print(Yellowtime[1]);
lcd.print(Yellowtime[2]);
lcd.print(Yellowtime[3]);
key = 0;}}

if (key != NO_KEY )
{if (key != ‘#’)
{Yellowtime[0] = Yellowtime[1];
Yellowtime[1] = Yellowtime[2];
Yellowtime[2] = Yellowtime[3];
Yellowtime[3] = key;
lcd.setCursor(0,1);
lcd.print(Yellowtime[0]);
lcd.print(Yellowtime[1]);
lcd.print(Yellowtime[2]);
lcd.print(Yellowtime[3]);}
else
{lcd.clear();
lcd.setCursor(0,0);
lcd.print(“Enter Greentime”);
Greentime[0] = ‘0’;
Greentime[1] = ‘0’;
Greentime[2] = ‘0’;
Greentime[3] = ‘0’;
lcd.setCursor(0,1);
lcd.print(Greentime[0]);
lcd.print(Greentime[1]);
lcd.print(Greentime[2]);
lcd.print(Greentime[3]);}}
if (key != NO_KEY)
{if (key != ‘#’)
{Greentime[0] = Greentime[1];
Greentime[1] = Greentime[2];
Greentime[2] = Greentime[3];
Greentime[3] = key;
lcd.setCursor(0,1);
lcd.print(Greentime[0]);
lcd.print(Greentime[1]);
lcd.print(Greentime[2]);
lcd.print(Greentime[3]);}
else
{lcd.clear();
lcd.setCursor(0,0);
lcd.print(“start”);}}

}

sketch_jun21a.ino (3.22 KB)

Please edit the code and do as I requested in #2.

Weedpharma

int pinled1 = 8;
int pinled2 = 9;
int pinled3 = 10;
int pinled4 = 18;
int pinled5 = 19;
char Redtime[4];
char Yellowtime[4];
char Greentime[4];

#include <Keypad.h>
const byte ROWS = 4; 
const byte COLS = 3;
char keys[ROWS][COLS] = {
  {'1','2','3'},
  {'4','5','6'},
  {'7','8','9'},
  {'*','0','#'},
};
byte rowPins[ROWS] = {17, 16, 15, 14}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {13, 12, 11}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );


#include <LiquidCrystal.h>
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);

void setup(){
  Serial.begin(9600);
  lcd.begin(16,2);
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("Enter Redtime:");
  Redtime[0] = '0';
  Redtime[1] = '0';
  Redtime[2] = '0';
  Redtime[3] = '0';
  lcd.setCursor(0,1);
  lcd.print(Redtime[0]);
  lcd.print(Redtime[1]);
  lcd.print(Redtime[2]);
  lcd.print(Redtime[3]);
  pinMode (pinled1, OUTPUT );
  pinMode (pinled2, OUTPUT );
  pinMode (pinled3, OUTPUT );
  pinMode (pinled4, OUTPUT );
  pinMode (pinled5, OUTPUT );
  digitalWrite(pinled1, LOW);
  digitalWrite(pinled2, LOW);
  digitalWrite(pinled3, LOW);
  digitalWrite(pinled4, LOW);
  digitalWrite(pinled5, LOW);
}
  
void loop(){
  char key = keypad.getKey();
  lcd.setCursor(0,0);
  if (key != NO_KEY )
    {if (key != '#')
       {Redtime[0] = Redtime[1];
        Redtime[1] = Redtime[2];
        Redtime[2] = Redtime[3];
        Redtime[3] = key;
        lcd.setCursor(0,1);
        lcd.print(Redtime[0]);
        lcd.print(Redtime[1]);
        lcd.print(Redtime[2]);
        lcd.print(Redtime[3]);}
     else 
       {lcd.clear();
        lcd.setCursor(0,0);
        lcd.print("Enter Yellowtime");
        Yellowtime[0] = '0';
        Yellowtime[1] = '0';
        Yellowtime[2] = '0';
        Yellowtime[3] = '0';
        lcd.setCursor(0,1);
        lcd.print(Yellowtime[0]);
        lcd.print(Yellowtime[1]);
        lcd.print(Yellowtime[2]);
        lcd.print(Yellowtime[3]);
        key = 0;}}
        

  if (key != NO_KEY )
     {if (key != '#')
        {Yellowtime[0] = Yellowtime[1];
         Yellowtime[1] = Yellowtime[2];
         Yellowtime[2] = Yellowtime[3];
         Yellowtime[3] = key;
         lcd.setCursor(0,1);
         lcd.print(Yellowtime[0]);
         lcd.print(Yellowtime[1]);
         lcd.print(Yellowtime[2]);
         lcd.print(Yellowtime[3]);}
      else 
        {lcd.clear();
         lcd.setCursor(0,0);
         lcd.print("Enter Greentime");
         Greentime[0] = '0';
         Greentime[1] = '0';
         Greentime[2] = '0';
         Greentime[3] = '0';
         lcd.setCursor(0,1);
         lcd.print(Greentime[0]);
         lcd.print(Greentime[1]);
         lcd.print(Greentime[2]);
         lcd.print(Greentime[3]);}}
    if (key != NO_KEY)
    {if (key != '#')
       {Greentime[0] = Greentime[1];
        Greentime[1] = Greentime[2];
        Greentime[2] = Greentime[3];
        Greentime[3] = key;
        lcd.setCursor(0,1);
        lcd.print(Greentime[0]);
        lcd.print(Greentime[1]);
        lcd.print(Greentime[2]);
        lcd.print(Greentime[3]);}
     else 
       {lcd.clear();
        lcd.setCursor(0,0);
        lcd.print("start");}}
              
             
        
        }

i am trying to get from the user three variables
he will enter it by keypad and it will show in the lcd

How would you enter the number in a calculator? You need some way to indicate that the end of the number has been entered. Store the characters in an array until the end-of-number marker (whatever you decide that is) is entered. Then, convert the stored string to a number and store as the red, yellow, or green time.

thanks so mush it works now but can you tell me how to change the string to a number