Hi guys,
I am currently working on a new project but, like always, I am a bit
struggling with the code.
My project include 12 LEDs connected to an Arduino Mega and a 4/3 keypad.
I would like to do binary counting using the LEDs and to change the rate of
increase or decrease using the keypad.
For example, by pressing 1 and "i++" or "i--"(I changed the "*" and "#" characters)
to either increase or decrease the counting by one.
Similarly, by pressing any other character, to either increase or decrease the counting
by its value.
Here is my code so far:
/* Binary counting using 12 LEDs and a keypad to change
the increasing or decreasing rate */
#include <Keypad.h>
int i;
int ledPin[12]={13,12,11,10,9,8,7,6,5,4,3,2};
int counter;
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'},
{'i--','10','i++'}
};
/* I want to use i-- and i++ to either increase
or decrease the binary counting */
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 keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup(){
for(i=0; i<12; i++){
pinMode(ledPin[i], OUTPUT); // sets the digital pins as output
char key = keypad.getKey();
if (key=1)
{
counter = i+1
}
else if(key=2)
{
counter= i+2
}
else if(key=3)
{
counter=i+3
}
else if etc....
}
}
Could you help?
Regards