For a project I am working on, I need to have a keypad control LED that turns on and off. The twist is that my main function can't be digitalWrite. Should I create an array, or should I create multiple voids? The LEDs need to be controlled with different values, as in 'A' = [on, off, off, on] and 'B' = [off, on, on, on].
Here is my code:
#include <Key.h>
#include <Keypad.h>
const byte ROWS = 4;
const byte COLS = 4;
//char variable is for character (such as the letters, numbers, and symbols)
char keyMatrix[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'},
};
byte rowPins[ROWS] = {46, 47, 48, 49};
byte colPins[COLS] = {50, 51, 52, 53};
Keypad myKeypad = Keypad(makeKeymap(keyMatrix), rowPins, colPins, ROWS, COLS);
const int rLED = 5;
const int wLED = 4;
const int gLED = 3;
const int bLED = 2;
void setup() {
//activates the serial monitor
Serial.begin(9600);
for(int pin = 2; pin <= 5; pin++){
pinMode(pin, OUTPUT);
}
}
void loop() {
//saving the keypress into a character variable
char theKeypress = myKeypad.getKey();
if(theKeypress){
switch(theKeypress){
case '1':
break;
case '2':
break;
case '3':
break;
case '4':
break;
case '5':
break;
case '6':
break;
case '7':
break;
case '8':
break;
case '9':
break;
case '0':
break;
case 'A':
break;
case 'B':
break;
case 'C':
break;
case 'D':
break;
case '#':
break;
case '*':
break;
}
}
}