I modified it a little, it should work now. Also now you can set the number of digits you want to enter, with "limit": default is 1.
#include <Keypad.h>
int ledPin[12]={
13,12,11,10,9,8,7,6,5,4,3,2};
int number[]={
0,0};
int limit = 1; // 1= 00 - 99, 2 = 000 - 999, 3 = 0000 - 4095 New variable, THE NUMBER OF DIGITS YOU NEED TO ENTER.
int count = 0;
int counter=0;
My_number = 0; // New variable
Final_Num = 0; // New variable
const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
char keys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};
byte rowPins[ROWS] = {31, 33, 35, 37}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {39, 41, 43}; //connect to the column pinouts of the keypad
Keypad customKeypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup(){
Serial.begin(9600);
for(counter=0; counter<12; counter++)
{
pinMode(ledPin[counter], OUTPUT); // sets the digital pins as output
}
}
void loop(){
char key = customKeypad.getKey();
/*if (key) {
Serial.println(key);
}*/
if (key) { // blocking from anything not needed
if (key != '*' && key !='#'){
Serial.print(key);
Serial.print(" ");
number[count] = key - '0';
if(count == limit) {
count = 0;
if( limit == 3) My_number = (number[0] *1000) + (number[1] * 100) + (number[2] * 10) + number[3];
else if( limit == 2) My_number = (number[0] *100) + (number[1] * 10) + number[2];
else My_number = (number[0] *10) + number[1] ;
Serial.print('\t');
Serial.println(My_number);
}
else {
count++;
}
}
}
// end of else if
//Serial.println(number);
if (key == '#') // increment binary counter
{
Final_Num += My_number;
if(Final_Num > 4095) {
Final_Num = 4095;
}
Serial.println(Final_Num);
//digitalWrite(13, HIGH);
//delay (1000);
for(counter = 0; counter < 12; counter++)
{
byte My_bits=bitRead(Final_Num,counter);
digitalWrite(counter + 2, My_bits);
//delay(1000);
} // end of increment counter
} // end of '#'
if (key == '*') // decrement binary counter
{
Final_Num -= My_number;
if(Final_Num < 0) {
Final_Num = 0;
}
Serial.println(Final_Num);
for(counter = 0; counter < 12; counter++)
{
byte My_bits = bitRead(Final_Num,counter);
digitalWrite(counter + 2, My_bits);
//delay(1000);
} // end of decrement counter
} // end of '*'
}//end of loop