Hi guys,
Sorry to bother you again but it still doesn't work.
This is my code:
/* Binary counting using 12 LEDs and a keypad to control
the increasing or decreasing rate by the value
of the key pressed*/
#include <Keypad.h>
int ledPin[12]={13,12,11,10,9,8,7,6,5,4,3,2};
int number=0;
int keyPressed=0;
int counter=0;
char firstKey;
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 (keyPressed ==1){
firstKey=key;
}
if ( keyPressed==2){
Serial.println(firstKey);
//Serial.println(number);
if (key == '#') // increment binary counter
{
Serial.println("i"+firstKey);
//digitalWrite(13, HIGH);
//delay (1000);
for(counter=0; counter< number; 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 '#'
if (key == '*') // decrement binary counter
{
for(counter; counter < number; 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 '*'
keyPressed=0;
} // end of keycount
} //end of if(key)
} // end of loop
It only works when I insert the first input then, nothing.
I mean that it turns all the LEDs on (the number key pressed)
and keeps them on.
What about the binary counting?
Regards