Simple keypad Project

I have a big project that involve arduino, part of the project is to use keypad to input date and time.
I did manage to write a code for that but the serial monitor show only the date part and I can input the date, but after that the program does not continue to input the time.
** I am writing the code in the setup part because I want this to tun one time, then I am going to use arduino delay function later to keep tracking of the time.

Here is the code :


  • Note: in Keypad [#] is cosidered as / for date (day/mon/year) & - is cosidered as : for (hour:min)
  • /
    #include <Keypad.h>

const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
char keys[ROWS][COLS] = {
byte rowPins[ROWS] = {12, 7, 8, 10}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {11, 13, 9}; //connect to the column pinouts

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

char entryStr[8];
int l=0;

void setup(){

int i=0;
int l=0;
// while (keypad.getKey()== NO_KEY){
if (i!=8) {
Serial.print("Date: ");
while (i!=8) {
char key2 = keypad.getKey();
if (key2 != NO_KEY){
entryStr*= key2;*

  • i++;*
  • Serial.print(key2);}*
  • }*
  • }*
  • else {*
  • if (l!=4) {*
  • Serial.print("/n ");// New line*
  • Serial.print("Time :");*
  • while (l!=4) {*
  • char key3 = keypad.getKey();*
  • if (key3 != NO_KEY){*
  • entryStr[l]= key3;*
  • l++;*
  • Serial.print(key3); }*
  • }*
  • }*
  • }*
  • }*
  • void loop(){*
  • }*
  • <-------------------------------------------------------------------------->*
  • I hope some body can help me figure the error in the code, because I can not put eye on the error.*

Rather than writing the code in the setup put it into its own method, that way it can be called from other places if needed.

It might help you if you write comments against each line of code explaining what it is doing. This way you may find the bug yourself. I have searched for bugs before and found them when I finally commented my code line by line.

Cheers Pete.

This is not looking good. Try isolating date and time code. A pseudo code should be like:

int date=get_date();
int time=get_time();
// Do something with date and time
int get_date()
  //Print prompt:
  //Collect key strokes for up to 2 keys
  //Valid date? No? start over
  //return date

//Same for time, just copy paste and change validity test.