Hi, i have a school project in which i have to get the day of the week of a date, and i used this code that i found:

``````#include <math.h>
int m;          // Month Entry
int d;          // Day Entry
int yy;         // Last 2 digits of the year (ie 2016 would be 16)
int yyyy;       // Year Entry
int c;          // Century (ie 2016 would be 20)
int mTable;     // Month value based on calculation table
int SummedDate; // Add values combined in prep for Mod7 calc
int DoW;        // Day of the week value (0-6)
int leap;       // Leap Year or not
int cTable;     // Century value based on calculation table

void setup()
{
Serial.begin(9600);
Serial.println("Day of the week calculator");
Serial.println("Enter date in numbers, mm/dd/yyyy)");
}

void loop() {
// if there's any serial available, read it
while (Serial.available() > 0)
{

m = Serial.parseInt();
d = Serial.parseInt();
yyyy = Serial.parseInt();

Serial.print(m);
Serial.print("/");
Serial.print(d);
Serial.print("/");
Serial.print(yyyy);

// Leap Year Calculation
if((fmod(yyyy,4) == 0 && fmod(yyyy,100) != 0) || (fmod(yyyy,400) == 0))
{ leap = 1; }
else
{ leap = 0; }

// Limit results to year 1900-2299 (to save memory)
while(yyyy > 2299)
{ yyyy = yyyy - 400; }
while(yyyy < 1900)
{ yyyy = yyyy + 400; }

// Calculating century
c = yyyy/100;

// Calculating two digit year
yy = fmod(yyyy, 100);

// Century value based on Table
if(c == 19) { cTable = 1; }
if(c == 20) { cTable = 0; }
if(c == 21) { cTable = 5; }
if(c == 22) { cTable = 3; }

// Jan and Feb calculations affected by leap years
if(m == 1)
{ if(leap == 1) { mTable = 6; }
else          { mTable = 0; }}
if(m == 2)
{ if(leap == 1) { mTable = 2; }
else          { mTable = 3; }}
// Other months not affected and have set values
if(m == 10) { mTable = 0; }
if(m == 8) { mTable = 2; }
if(m == 3 || m == 11) { mTable = 3; }
if(m == 4 || m == 7) { mTable = 6; }
if(m == 5) { mTable = 1; }
if(m == 6) { mTable = 4; }
if(m == 9 || m == 12) { mTable = 5; }

// Enter the data into the formula
SummedDate = d + mTable + yy + (yy/4) + cTable;

// Find remainder
DoW = fmod(SummedDate,7);

// Output result
Serial.print(" = ");

// Remainder determines day of the week
if(DoW == 0) { Serial.println("Saturday"); }
if(DoW == 1) { Serial.println("Sunday"); }
if(DoW == 2) { Serial.println("Monday"); }
if(DoW == 3) { Serial.println("Tuesday"); }
if(DoW == 4) { Serial.println("Wednesday"); }
if(DoW == 5) { Serial.println("Thursday"); }
if(DoW == 6) { Serial.println("Friday"); }

}
}
``````

This works fine, but now i need to use a keypad, instead of the keyboard, and I don’t know how to do that.
I’m trying to use a 4x4 keypad, every attempt at doing it just printed one number and nothing more.
Can anyone help me? Thanks.

So you have some code for a keypad that you're having trouble with and you'd like some help. But instead of posting that you post some other different code that works. How are we supposed to help with code we can't see?

When you have a problem with your car, do you take your friends car to the mechanic and ask what is wrong with yours?

Well, I didn’t think it would be necessary to post the other part of the code, but here is the code that didn’t work

``````#include <math.h>

const byte ROWS = 4;
const byte COLS = 4;

char hexaKeys[ROWS][COLS] = {
{'1', '2', '3', '/'},
{'4', '5', '6', 'A'},
{'7', '8', '9', 'B'},
{'*', '0', '#', 'C'}
};

byte rowPins[ROWS] = {9, 8, 7, 6};
byte colPins[COLS] = {5, 4, 3, 2};

int m;          // Month Entry
int d;          // Day Entry
int yy;         // Last 2 digits of the year (ie 2016 would be 16)
int yyyy;       // Year Entry
int c;          // Century (ie 2016 would be 20)
int mTable;     // Month value based on calculation table
int SummedDate; // Add values combined in prep for Mod7 calc
int DoW;        // Day of the week value (0-6)
int leap;       // Leap Year or not
int cTable;     // Century value based on calculation table

void setup()
{
Serial.begin(9600);
Serial.println("Day of the week calculator");
Serial.println("Enter date in numbers, mm/dd/yyyy)");
}

void loop() {
// if there's any serial available, read it

if (customKey){
Serial.println(customKey);
}
if (Serial.available() > 0)
{

m = Serial.parseInt();
d = Serial.parseInt();
yyyy = Serial.parseInt();

Serial.print(m);
Serial.print("/");
Serial.print(d);
Serial.print("/");
Serial.print(yyyy);

// Leap Year Calculation
if((fmod(yyyy,4) == 0 && fmod(yyyy,100) != 0) || (fmod(yyyy,400) == 0))
{ leap = 1; }
else
{ leap = 0; }

// Limit results to year 1900-2299 (to save memory)
while(yyyy > 2299)
{ yyyy = yyyy - 400; }
while(yyyy < 1900)
{ yyyy = yyyy + 400; }

// Calculating century
c = yyyy/100;

// Calculating two digit year
yy = fmod(yyyy, 100);

// Century value based on Table
if(c == 19) { cTable = 1; }
if(c == 20) { cTable = 0; }
if(c == 21) { cTable = 5; }
if(c == 22) { cTable = 3; }

// Jan and Feb calculations affected by leap years
if(m == 1)
{ if(leap == 1) { mTable = 6; }
else          { mTable = 0; }}
if(m == 2)
{ if(leap == 1) { mTable = 2; }
else          { mTable = 3; }}
// Other months not affected and have set values
if(m == 10) { mTable = 0; }
if(m == 8) { mTable = 2; }
if(m == 3 || m == 11) { mTable = 3; }
if(m == 4 || m == 7) { mTable = 6; }
if(m == 5) { mTable = 1; }
if(m == 6) { mTable = 4; }
if(m == 9 || m == 12) { mTable = 5; }

// Enter the data into the formula
SummedDate = d + mTable + yy + (yy/4) + cTable;

// Find remainder
DoW = fmod(SummedDate,7);

// Output result
Serial.print(" = ");

// Remainder determines day of the week
if(DoW == 0) { Serial.println("Saturday"); }
if(DoW == 1) { Serial.println("Sunday"); }
if(DoW == 2) { Serial.println("Monday"); }
if(DoW == 3) { Serial.println("Tuesday"); }
if(DoW == 4) { Serial.println("Wednesday"); }
if(DoW == 5) { Serial.println("Thursday"); }
if(DoW == 6) { Serial.println("Friday"); }

}
}
``````

The code just prints one number, and i need to print a string in this form : mm/dd/yyyy
Then i need to read said string so that the calculator can give me a result.
Sorry if i didn’t explain it properly. Thanks

claudiomaxter23: Well, I didn't think it would be necessary to post the other part of the code, but here is the code that didn't work

How can I tell you what's wrong with it or how to fix it without seeing it? Seriously...

``````char customKey = customKeypad.getKey();
``````

That command gets one character. To get more than one, you will need an array and fill each spot in with another read of the keypad. It's really not that different from reading from Serial except that you don't have the parseInt crutch to lean on. You have to read characters one at a time with the getKey() command.

Set up an array of how many char it will take to hold your date. On each pass of the loop check to see if you got a new key. If you do, then add it to the next spot in the array. You'll need a variable to keep up with what spot in the array you're on.

Have a look around the internet. Google "Arduino read multi-digit number from keypad" or something like that. That topic has been covered pretty well and will show exactly what you need to do.

Thanks! I think i got the idea, i'll see if i can set up the array an use it, Thanks again.