/** * Matrix Keypad * * This example shows how to use the library to perform a non blocking scanning of a generic keypad. * * @version 1.1.0 * @author Victor Henrique Salvi */ #include "MatrixKeypad.h" #include const uint8_t rown = 4; //4 rows const uint8_t coln = 8; //3 columns uint8_t rowPins[rown] = {29, 28, 27, 26}; //frist row is connect to pin 10, second to 9... uint8_t colPins[coln] = {37, 36, 35, 34, 33, 32, 31, 30}; //frist column is connect to pin 6, second to 5... char keymap[rown][coln] = {{'0','1','2','3','4','5','6','7'}, {'0','1','2','3','4','5','6','7'}, {'0','1','2','3','4','5','6','7'}, {'0','1','2','3','4','5','6','7'},}; MatrixKeypad_t *keypad; //keypad is the variable that you will need to pass to the other functions char key; void setup() { Serial.begin(115200); pinMode(LED_BUILTIN, OUTPUT); keypad = MatrixKeypad_create((char*)keymap /* don't forget to do this cast */, rowPins, colPins, rown, coln); //creates the keypad object } void loop() { MatrixKeypad_scan(keypad); //scans for a key press event if(MatrixKeypad_hasKey(keypad)){ //if a key was pressed key = MatrixKeypad_getKey(keypad); //get the key Serial.print(key); //prints the pressed key to the serial output } blink (); //blinks a led (non-blocking) roughly each second to show that the keypad scanning won't block the program delay(20); //do something } /* blinks a led roughly each second */ void blink () { static int led_state = LOW; static long time = 0; if(millis() - time > 500) { if(led_state == HIGH){ led_state = LOW; } else { led_state = HIGH; } digitalWrite(LED_BUILTIN, led_state); time = millis(); } }