#include <Keypad.h>
#include <ezBuzzer.h>
const int BUZZER_PIN = 11;
const int ROW_NUM = 4; // four rows
const int COLUMN_NUM = 4; // four columns
char keys[ROW_NUM][COLUMN_NUM] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
byte pin_rows[ROW_NUM] = {9, 8, 7, 6}; // connect to the row pinouts of the keypad
byte pin_column[COLUMN_NUM] = {5, 4, 3, 2}; // connect to the column pinouts of the keypad
Keypad keypad = Keypad(makeKeymap(keys), pin_rows, pin_column, ROW_NUM, COLUMN_NUM );
ezBuzzer buzzer(BUZZER_PIN); // create ezBuzzer object that attach to a pin;
void setup() {
Serial.begin(9600);
}
void loop() {
buzzer.loop(); // MUST call the buzzer.loop() function in loop()
char key = keypad.getKey();
if (key) {
if (key == '1')
delay(1000);
if (key == '2')
delay(2000);
if (key == '3')
delay(3000);
if (key == '4')
delay(4000);
if (key == '5')
delay(5000);
if (key == '6')
delay(6000);
if (key == '7')
delay(7000);
if (key == '8')
delay(8000);
if (key == '9')
delay(9000);
if (key == '10')
delay(10000);
Serial.print(key); // prints key to serial monitor
buzzer.beep(100); // generates a 100ms beep
}
}