#include <Keypad.h>
// Defines how many rows and columns there are
const byte ROWS = 4;
const byte COLS = 4;
// Define name of keys
char hexaKeys[ROWS][COLS] = {
{'1', '2', '3', '4'},
{'5', '6', '7', '8'},
{'A', 'B', 'C', 'D'},
{'E', 'F', 'G', 'H'}
};
byte colPins[ROWS] = {9, 8, 7, 6};
byte rowPins[COLS] = {5, 4, 3, 2};
Keypad customKeypad = Keypad(makeKeymap(hexaKeys), colPins, rowPins, ROWS, COLS);
// Define notes
#define NOTE_C 523
#define NOTE_CS 554
#define NOTE_D 587
#define NOTE_E 659
#define NOTE_F 698
#define NOTE_FS 740
#define NOTE_G 784
#define NOTE_A 880
#define NOTE_B 988
#define NOTE_C2 1047
#define NOTE_CS2 1109
#define NOTE_D2 1175
#define NOTE_E2 1319
#define NOTE_F2 1397
#define NOTE_FS2 1480
#define NOTE_G2 1568
// Change this depending on your pin on the Arduino
const int buzzer = 11;
void setup() {
Serial.begin(9600);
}
void loop() {
int customKey = customKeypad.getKey();
if (customKey == '1') {
tone(buzzer, NOTE_C, 200);
}
if (customKey == '2') {
tone(buzzer, NOTE_CS, 200);
}
if (customKey == '3') {
tone(buzzer, NOTE_D, 200);
}
if (customKey == '4') {
tone(buzzer, NOTE_E, 200);
}
if (customKey == '5') {
tone(buzzer, NOTE_F, 200);
}
if (customKey == '6') {
tone(buzzer, NOTE_FS, 200);
}
if (customKey == '7') {
tone(buzzer, NOTE_G, 200);
}
if (customKey == '8') {
tone(buzzer, NOTE_A, 200);
}
if (customKey == 'A') {
tone(buzzer, NOTE_B, 200);
}
if (customKey == 'B') {
tone(buzzer, NOTE_C2, 200);
}
if (customKey == 'C') {
tone(buzzer, NOTE_CS2, 200);
}
if (customKey == 'D') {
tone(buzzer, NOTE_D2, 200);
}
if (customKey == 'E') {
tone(buzzer, NOTE_E2, 200);
}
if (customKey == 'F') {
tone(buzzer, NOTE_F2, 200);
}
if (customKey == 'G') {
tone(buzzer, NOTE_FS2, 200);
}
if (customKey == 'H') {
tone(buzzer, NOTE_G2, 200);
}
}
Comments