Thanks,
I changed the code following the last suggestion.
This is the code:
#include <Keypad.h>
int ledPin[12]={
13,12,11,10,9,8,7,6,5,4,3,2};
int number[]={
0,0};
int count = 0;
int keyPressed=0;
int counter=0;
int sum=0;
char firstKey;
char secondKey;
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 == 1) {
count = 0;
sum=(number[0] *10)+number[1];
Serial.print('\t');
Serial.println(sum);
}
else {
count++;
}
}
}
// end of else if
//Serial.println(number);
if (key == '#') // increment binary counter
{
Serial.println(sum++);
//digitalWrite(13, HIGH);
//delay (1000);
for(counter=0; counter<= 12; counter++)
{
byte My_bits=bitRead(sum,counter);
digitalWrite(counter, My_bits);
//delay(1000);
} // end of increment counter
} // end of '#'
if (key == '*') // decrement binary counter
{
Serial.println(sum--);
for(counter; counter > sum; counter-- )
{
if (counter < 0) counter = 0;
byte My_bits = bitRead(sum,counter);
digitalWrite(counter, My_bits);
//delay(1000);
} // end of decrement counter
} // end of '*'
}//end of loop
]
It shows some LEDs on but it's not in binary.
At least I know how to count in binary.
I guess I am very close to my solution.