Code:
// Button Box Sketch Initial Prototype
// Rev. 1.2
// Travis Mihm
// Initialize the integers for the Row and Column Matrix
const int numRows = 12; // Number of Rows is assigned as a constant integer
const int numCols = 7; // Number of Columns is assigned as a constant integer
const int debounceTime = 200; // Set the milliseconds for debounce as a constant integer
//Use Keymap to define the character for the buttons when pressed
const char keymap[numRows][numCols] = // the keymap assignments remain constant characters
{
{'A','B','C','D','a','y','m'},
{'E','F','G','H','b','z','n'},
{'I','J','K','L','c','0','o'},
{'*','*','*','*','d','1','p'},
{'*','*','*','*','e','2','q'},
{'*','*','*','*','f','3','r'},
{'*','*','*','*','g','4','s'},
{'M','N','O','P','h','5','t'},
{'*','*','*','*','i','6','u'},
{'Q','R','S','T','j','7','v'},
{'*','*','*','*','k','8','w'},
{'U','V','W','X','l','9','x'},
};
//Set array for pins being used
const int rowPins[numRows] = {3, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21}; //Assign constant integers relating the number of rows to their corresponding pins
const int colPins[numCols] = {10, 9, 8, 7, 6, 5, 4}; //Assign constant integers relating the number of columns to their corresponding pins
//Begin setup procedure
void setup()
{
Serial.begin(9600); // Start conversation with the serial port
for (int row = 0; row < numRows; row++) // For loop; Initial condition is the ingeger "row" set at zero. It then tests to see of the row integer is less than
// the numRows integer. If true, the statement {} runs, and the integer "row" is incremented. If false, the for loop
// terminates
{
pinMode(rowPins[row], INPUT); // Set row pins as input type
digitalWrite(rowPins[row], HIGH); // Turn on Pull-Ups
}
for (int column = 0; column < numCols; column++) // Same loop with the rows, but for the columns now
{
pinMode(colPins[column], OUTPUT); // Set column pins as output pins
digitalWrite(colPins[column], HIGH); // Set all columns inactive initially
}
}
// The "for" loops were to set the initial ready-conditions for the board. Now the code begins the body of the loop procedures to output which buttons get pressed
void loop()
{
char key = getKey();
if( key != 0)
{
Serial.print("You pressed ");
Serial.println(key);
Keyboard.press(key);
Keyboard.release(key);
}
}
// returns the the key pressed, or 0 if no key is pressed.
char getKey()
{
char key = 0;
for (int column = 0; column < numCols; column++)
{
digitalWrite(colPins[column], LOW); //Activate (column number)
for(int row = 0; row < numRows; row++) //Scan rows on this column for a
//key press
{
if(digitalRead(rowPins[row]) == LOW) //When key is pressed...
{
delay(debounceTime); // Set the time for the debounceTime integer
while(digitalRead(rowPins[row]) == LOW); // While the row for the column being scanned is still active
key = keymap[row][column]; // The key integer is now whatever was set in the keymap function under the current row and column being scanned
}
}
digitalWrite(colPins[column], HIGH); // Deactivate the current column
}
return key; // returns the current key intiger to the getKey function. This ends the getKey loop and starts it over again.
}
However, I still can't seem to get the double quotations to work and name each point on the matrix a string of characters. I was wondering if I could use the KEY_A, KEY_UP, etc. instead of individual characters. But if I simply substitute those in nothing works, and I haven't entirely figured out how to use them. Paul, which lines of code do I need to add the const qualifier to to make that work? I think I've gone into the twisted world of over-thinking things outside my scope