/*
* Created by ArduinoGetStarted.com
*
* This example code is in the public domain
*
* Tutorial page: https://arduinogetstarted.com/tutorials/arduino-keypad-beep
*/
#include <Keypad.h>
#define buzz 10
#define LED 12
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 );
// create ezBuzzer object that attach to a pin;
void setup() {
Serial.begin(9600);
pinMode(buzz, OUTPUT);
pinMode(LED, OUTPUT);
}
void loop() {
char key = keypad.getKey();
if (key) {digitalWrite(LED, HIGH);delay(50);}else{digitalWrite(LED, LOW);}
if (key=='1') {tone(buzz,480);delay(200);noTone(buzz);}
if (key=='2') {tone(buzz,480);delay(200);noTone(buzz);}
if (key=='3') {tone(buzz,450);delay(200);noTone(buzz);}
if (key=='4') {tone(buzz,450);delay(200);noTone(buzz);}
if (key=='5') {tone(buzz,400);delay(200);noTone(buzz);}
if (key=='6') {tone(buzz,400);delay(200);noTone(buzz);}
if (key=='7') {tone(buzz,360);delay(200);noTone(buzz);}
if (key=='8') {tone(buzz,360);delay(200);noTone(buzz);}
if (key=='9') {tone(buzz,320);delay(200);noTone(buzz);}
if (key=='A') {tone(buzz,320);delay(200);noTone(buzz);}
if (key=='B') {tone(buzz,300);delay(200);noTone(buzz);}
if (key=='C') {tone(buzz,300);delay(200);noTone(buzz);}
if (key=='D') {tone(buzz,270);delay(200);noTone(buzz);}
if (key=='0') {tone(buzz,270);delay(200);noTone(buzz);}
if (key=='*') {tone(buzz,240);delay(200);noTone(buzz);}
if (key=='#') {tone(buzz,240);delay(200);noTone(buzz);}
}