#include <Keypad.h>
#define buzz 13
const uint8_t ROWS = 4;
const uint8_t COLS = 4;
char keys[ROWS][COLS] = {
{ '1', '2', '3', },
{ '4', '5', '6', },
{ '7', '8', '9', },
{ '*', '0', '#', }
};
uint8_t colPins[COLS] = { 5, 4, 3, 2 }; // Pins connected to C1, C2, C3, C4
uint8_t rowPins[ROWS] = { 9, 8, 7, 6 }; // Pins connected to R1, R2, R3, R4
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
void setup() {
Serial.begin(9600);
pinMode(buzz, OUTPUT);
Serial.println("Press a key");
}
void loop() {
char presskey = keypad.getKey();
if (presskey){
Serial.print("Key pressed");
Serial.println(presskey);
if(presskey == '1'){
digitalWrite(buzz, HIGH);
delay(100);
digitalWrite(buzz, LOW);
delay(100);
tone(buzz, 25, 200);
delay(400);
tone(buzz, 61, 200);
delay(400);
tone(buzz, 107, 200);
delay(400);
tone(buzz, 142, 200);
delay(400);
}
if(presskey == '2'){
tone(buzz, 164, 200);
delay(400);
tone(buzz, 217, 200);
delay(400);
tone(buzz, 267, 200);
delay(400);
tone(buzz, 341, 200);
delay(400);
}
if(presskey == '3'){
tone(buzz, 371, 200);
delay(400);
tone(buzz, 416, 200);
delay(400);
tone(buzz, 472, 200);
delay(400);
tone(buzz, 517, 200);
delay(400);
}
if(presskey == '4'){
tone(buzz, 582, 200);
delay(400);
tone(buzz, 662, 200);
delay(400);
tone(buzz, 712, 200);
delay(400);
tone(buzz, 760, 200);
delay(400);
}
if(presskey == '5'){
tone(buzz, 796, 200);
delay(400);
tone(buzz, 821, 200);
delay(400);
tone(buzz, 892, 200);
delay(400);
tone(buzz, 946, 200);
delay(400);
}
if(presskey == '6'){
tone(buzz, 987, 200);
delay(400);
tone(buzz, 1081, 200);
delay(400);
tone(buzz, 1164, 200);
delay(400);
tone(buzz, 1282, 200);
delay(400);
}
if(presskey == '7'){
tone(buzz, 1396, 200);
delay(400);
tone(buzz, 1462, 200);
delay(400);
tone(buzz, 1542, 200);
delay(400);
tone(buzz, 1689, 200);
delay(400);
}
if(presskey == '8'){
tone(buzz, 1841, 200);
delay(400);
tone(buzz, 1962, 200);
delay(400);
tone(buzz, 2031, 200);
delay(400);
tone(buzz, 2145, 200);
delay(400);
}
if(presskey == '9'){
tone(buzz, 2268, 200);
delay(400);
tone(buzz, 2387, 200);
delay(400);
tone(buzz, 2532, 200);
delay(400);
tone(buzz, 2743, 200);
delay(400);
}
}
}