// led matrix row connection int ledAnode[4] = {14, 15, 16, 17}; // led matrix column connection int ledCathode[4] = {18, 19, 0, 1}; // pixel initialization of led matrix int pixel[4][4] = {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}; // row connection for sensor matrix int r1 = 6; int r2 = 7; int r3 = 8; int r4 = 9; // column connection of sersor matrix int c1 = 10; int c2 = 11; int c3 = 12; int c4 = 13; int key = 0; // the setup routine runs once when you press reset: void setup() { // initialize the digital pin as an output. for(int i=0; i<4; i++){ // initialize the output pins: pinMode(ledAnode[i], OUTPUT); pinMode(ledCathode[i], OUTPUT); // take the col pins (i.e. the cathodes) high to ensure that // the LEDS are off: digitalWrite(ledCathode[i], HIGH); } Serial.begin(9600); // row pin as output pinMode(r1, OUTPUT); pinMode(r2, OUTPUT); pinMode(r3, OUTPUT); pinMode(r4, OUTPUT); // column pin as input pinMode(c1, INPUT); pinMode(c2, INPUT); pinMode(c3, INPUT); pinMode(c4, INPUT); // activate internal pill up resistor digitalWrite(c1, HIGH); digitalWrite(c2, HIGH); digitalWrite(c3, HIGH); digitalWrite(c4, HIGH); } // the loop routine runs over and over again forever: void loop() { // identify the sensor on which finger is placed keypad_scan(); // determine which led should turn on keypad_value(); // turn on the corresponding led refreshScreen(); } void refreshScreen() { // iterate over the rows (anodes): for (int row = 0; row < 4; row++) { // take the row pin (anode) high: digitalWrite(ledAnode[row], HIGH); // iterate over the cols (cathodes): for (int col = 0; col < 4; col++) { // get the state of the current pixel; int currentPixel = !pixel[row][col]; // when the row is HIGH and the col is LOW, // the LED where they meet turns on: digitalWrite(ledCathode[col], currentPixel); // turn the pixel off: if (currentPixel == LOW) { digitalWrite(ledCathode[col], HIGH); } } // take the row pin low to turn off the whole row: digitalWrite(ledAnode[row], LOW); } } void keypad_value() { switch (key) { case 1: pixel[0][0] = 1; break; case 2: pixel[0][1] = 1; break; case 3: pixel[0][2] = 1; break; case 4: pixel[0][3] = 1; break; case 5: pixel[1][0] = 1; break; case 6: pixel[1][1] = 1; break; case 7: pixel[1][2] = 1; break; case 8: pixel[1][3] = 1; break; case 9: pixel[2][0] = 1; break; case 10: pixel[2][1] = 1; break; case 11: pixel[2][2] = 1; break; case 12: pixel[2][3] = 1; break; case 13: pixel[3][0] = 1; break; case 14: pixel[3][1] = 1; break; case 15: pixel[3][2] = 1; break; case 16: pixel[3][3] = 1; break; default: Serial.println(key); //} } } void keypad_scan(){ digitalWrite(r1, HIGH); digitalWrite(r2, LOW); digitalWrite(r3, LOW); digitalWrite(r4, LOW); if(digitalRead(c1)==LOW) key = 1; else if(digitalRead(c2)==LOW) key = 2; else if(digitalRead(c3)==LOW) key = 3; else if(digitalRead(c4)==LOW) key = 4; digitalWrite(r1, LOW); digitalWrite(r2, HIGH); digitalWrite(r3, LOW); digitalWrite(r4, LOW); if(digitalRead(c1)==LOW) key = 5; else if(digitalRead(c2)==LOW) key = 6; else if(digitalRead(c3)==LOW) key = 7; else if(digitalRead(c4)==LOW) key = 8; digitalWrite(r1, LOW); digitalWrite(r2, LOW); digitalWrite(r3, HIGH); digitalWrite(r4, LOW); if(digitalRead(c1)==LOW) key = 9; else if(digitalRead(c2)==LOW) key = 10; else if(digitalRead(c3)==LOW) key = 11; else if(digitalRead(c4)==LOW) key = 12; digitalWrite(r1, LOW); digitalWrite(r2, LOW); digitalWrite(r3, LOW); digitalWrite(r4, HIGH); if(digitalRead(c1)==LOW) key = 13; else if(digitalRead(c2)==LOW) key = 14; else if(digitalRead(c3)==LOW) key = 15; else if(digitalRead(c4)==LOW) key = 16; }