#include <Keypad.h>
const int soundPin = 2;
const byte ROWS = 4;
const byte COLS = 4;
int f1=697;
int f2=770;
int f3=852;
int f4=941;
int F1=1209;
int F2=1336;
int F3=1477;
int F4=1633;
char keys[ROWS][COLS] =
{
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte rowPins[ROWS] = {A0,A1,A2,A3};
byte colPins[COLS] = {3,4,5,6};
Keypad customKeypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
void setup()
{
pinMode(soundPin, OUTPUT);
Serial.begin(9600);
}
void loop()
{
char customKey = customKeypad.getKey();
if (customKey == '0') {
tone (soundPin, (f4+F2)/2, 100);
Serial.println((f4+F2)/2);
}
if (customKey == '1') {
tone (soundPin, (f1+F1)/2, 100);
Serial.println((f1+F1)/2);
}
if (customKey == '2') {
tone (soundPin, (f1+F2)/2, 100);
Serial.println((f1+F2)/2);
}
if (customKey == '3') {
tone (soundPin, (f1+F3)/2, 100);
Serial.println((f1+F3)/2);
}
if (customKey == '4') {
tone (soundPin, (f2+F1)/2, 100);
Serial.println((f2+F1)/2);
}
if (customKey == '5') {
tone (soundPin, (f2+F2)/2, 100);
Serial.println((f2+F2)/2);
}
if (customKey == '6') {
tone (soundPin, (f2+F3)/2, 100);
Serial.println((f2+F3)/2);
}
if (customKey == '7') {
tone (soundPin, (f3+F1)/2, 100);
Serial.println((f3+F1)/2);
}
if (customKey == '8') {
tone (soundPin, (f3+F2)/2, 100);
Serial.println((f3+F2)/2);
}
if (customKey == '9') {
tone (soundPin, (f3+F3)/2, 100);
Serial.println((f3+F3)/2);
}
if (customKey == 'A') {
tone (soundPin, (f1+F4)/2, 100);
Serial.println((f1+F4)/2);
}
if (customKey == 'B') {
tone (soundPin, (f2+F4)/2, 100);
Serial.println((f2+F4)/2);
}
if (customKey == 'C') {
tone (soundPin, (f3+F4)/2, 100);
Serial.println((f3+F4)/2);
}
if (customKey == 'D') {
tone (soundPin, (f4+F4)/2, 100);
Serial.println((f4+F4)/2);
}
if (customKey == '*') {
tone (soundPin, (f4+F1)/2, 100);
Serial.println((f4+F1)/2);
}
if (customKey == '#') {
tone (soundPin, (f4+F3)/2, 100);
Serial.println((f4+F3)/2);
}
// delay(50);
}