Created
October 19, 2012 11:39
-
-
Save Crenshinibon/3917754 to your computer and use it in GitHub Desktop.
Keymatrix polling Function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static void scanKeys(){ | |
//iterate over columns | |
for(int currentColumn = 0; currentColumn < COL_COUNT; currentColumn ++){ | |
digitalWrite(cols[currentColumn],HIGH); | |
//scan rows | |
for(int y = 0; y < ROW_COUNT; y++){ | |
Key* key = keyMatrix[currentColumn][y]; | |
if(key != NOKEY){ | |
int state = digitalRead(rows[y]); | |
if((state == HIGH && !key->pressed) || (state == LOW && key->pressed)){ | |
//The toggleKey function actually does the debouncing. | |
//It returns true if the state really changed. | |
//And false otherwise | |
if(toggleKey(key)){ | |
keyChanged = true; | |
} | |
} | |
//collect report data | |
if(key->pressed){ | |
if(pressedKeyIndex < MAX_KEYS_PRESSED){ | |
pressedKeys[pressedKeyIndex] = key; | |
pressedKeyIndex++; | |
} | |
} | |
} | |
} | |
digitalWrite(cols[currentColumn],LOW); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment