Hi all,
I am working on a project with a hacked phone that has a 3x4 keypad. I was able to figure out the wiring and how it works with the keypad library. My question is that– currently I can get to display numbers, 1 to 9 on the serial monitor but what if I want to display 2 digit numbers? I am trying to have different numbers pressed (values between 1- 52) to pull up different processing sketches.
#include <Keypad.h>
//char* num[] = {"01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20"};
char* num01 = "01";
char* num02 = "02";
char* num03 = "03";
char* num04 = "04";
char* num05 = "05";
char* num06 = "06";
char* num07 = "07";
char* num08 = "08";
char* num09 = "09";
char* num10 = "10";
char* num11 = "11";
char* num12 = "12";
char* num21 = "21";
char* num22 = "22";
int count = 0;
const byte ROWS = 4; // Four rows
const byte COLS = 3; // Three columns
// keymap
char keys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};
// Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins.
byte rowPins[ROWS] = { 9, 8, 7, 6 };
// Connect keypad COL0, COL1 and COL2 to these Arduino pins.
byte colPins[COLS] = { 10, 11, 12 };
// Create the Keypad
Keypad kpd = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup()
{
Serial.begin(9600);
}
void loop(){
char key = kpd.getKey();
if (key == '*' || key == '#')
{
count = 0;
}
//if (key == num[count])
//{
//count ++;
//}
//if (count == 2)
//{
//Serial.println (num);
//count = 0;
//}
//////
if (key == num01[count])
{
count ++;
}
if (count == 2)
{
Serial.println ("01");
count = 0;
}
//////
if (key == num02[count])
{
count ++;
}
if (count == 2)
{
Serial.println ("02");
count = 0;
}
//////
if (key == num03[count])
{
count ++;
}
if (count == 2)
{
Serial.println ("03");
count = 0;
}
//////
if (key == num04[count])
{
count ++;
}
if (count == 2)
{
Serial.println ("04");
count = 0;
}
//////
if (key == num05[count])
{
count ++;
}
if (count == 2)
{
Serial.println ("05");
count = 0;
}
//////
if (key == num06[count])
{
count ++;
}
if (count == 2)
{
Serial.println ("06");
count = 0;
}
//////
if (key == num07[count])
{
count ++;
}
if (count == 2)
{
Serial.println ("07");
count = 0;
}
//////
if (key == num08[count])
{
count ++;
}
if (count == 2)
{
Serial.println ("08");
count = 0;
}
//////
if (key == num09[count])
{
count ++;
}
if (count == 2)
{
Serial.println ("09");
count = 0;
}
//////
if (key == num10[count])
{
count ++;
}
if (count == 2)
{
Serial.println ("10");
count = 0;
}
}
With the current code that I have, whenever I try to add anymore numbers, for example 10, 11, 21, etc the serial monitor would print out different numbers...
I am hoping it is just something simple.
cheers,