Skip to content

Instantly share code, notes, and snippets.

@Crenshinibon
Created October 19, 2012 11:39
Show Gist options
  • Save Crenshinibon/3917754 to your computer and use it in GitHub Desktop.
Save Crenshinibon/3917754 to your computer and use it in GitHub Desktop.
Keymatrix polling Function
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