HazardsMind:
According to your code, you have everything inside keypress2, and with the "key != '*' && key !='#' ", it will never get to the other buttons. You need to fix your brackets. Keypress1 is fine, now do the same thing for Keypress2. You can keep the sum inside, but everything else must come out.
Thanks,
I really don't know how to close that bracket or more exactly, where is
the right place to put it. It shows me lots of errors.
Look, this is my modified code:
#include <Keypad.h>
int ledPin[12]={13,12,11,10,9,8,7,6,5,4,3,2};
int number1=0;
int number2=0;
int keyPressed=0;
int counter=0;
int sum=0;
char firstKey;
char secondKey;
long previousMillis = 0;
long interval = 1000;
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
keyPressed= keyPressed+1;
if (key != '*' && key !='#'){
// number =key - '0' ; // convert key to its value
} // end of sort
if (key != '*' && key !='#'&& keyPressed ==1){
number1= key - '0';
firstKey=key;
} // end of key==1
else if (key != '*' && key !='#'&& keyPressed==2){
number2= key - '0';
secondKey=key;
sum=(number1 *10)+number2;
// end or key==2
//Serial.println(number);
if (sum){
char key = customKeypad.getKey();
// I'm not sure about this loop
if (key == '#') // increment binary counter
{
Serial.println("i"+firstKey);
//digitalWrite(13, HIGH);
//delay (1000);
for(counter=0; counter< sum; counter++){
//digitalWrite(ledPin[counter-1], HIGH);
digitalWrite(ledPin[counter], HIGH);
unsigned long currentMillis = millis();
if(currentMillis - previousMillis > interval) {
previousMillis = currentMillis;
} // end of millis
} // end of increment counter
} // end of '#'
else if (key == '*') // decrement binary counter
{
for(counter; counter < sum; counter-- ){
if (counter < 0) counter = 0; // checks to see if
// counter does past zero then set it back to zero
digitalWrite(ledPin[counter], LOW);
unsigned long currentMillis = millis();
if(currentMillis - previousMillis > interval) {
previousMillis = currentMillis;
} // end of millis
} // end of decrement counter
} // end of '*'
} // end of sum
keyPressed=0;
} // end of keycount
}//end of if(key)
}// end of loop
If I close the bracket after "end of key==2", see above, I also
have to close the loop which is worse.
I've been trying since this morning.
I really don't know