Components and supplies
1
Arduino UNO
1
Breadboard (generic)
1
Buzzer, Piezo
11
Jumper wires (generic)
1
4x4 Button Pad
1
Resistor 220 ohm
Apps and platforms
1
Arduino IDE
Project description
Code
Keypad Music Player Code
c_cpp
1#include <Keypad.h> 2 3 4// Defines how many rows and columns there are 5const byte ROWS = 4; 6const byte COLS = 4; 7 8// Define name of keys 9char hexaKeys[ROWS][COLS] = { 10 {'1', '2', '3', '4'}, 11 {'5', '6', '7', '8'}, 12 {'A', 'B', 'C', 'D'}, 13 {'E', 'F', 'G', 'H'} 14}; 15 16byte colPins[ROWS] = {9, 8, 7, 6}; 17byte rowPins[COLS] = {5, 4, 3, 2}; 18 19Keypad customKeypad = Keypad(makeKeymap(hexaKeys), colPins, rowPins, ROWS, COLS); 20 21// Define notes 22#define NOTE_C 523 23#define NOTE_CS 554 24#define NOTE_D 587 25#define NOTE_E 659 26#define NOTE_F 698 27#define NOTE_FS 740 28#define NOTE_G 784 29#define NOTE_A 880 30#define NOTE_B 988 31#define NOTE_C2 1047 32#define NOTE_CS2 1109 33#define NOTE_D2 1175 34#define NOTE_E2 1319 35#define NOTE_F2 1397 36#define NOTE_FS2 1480 37#define NOTE_G2 1568 38 39// Change this depending on your pin on the Arduino 40const int buzzer = 11; 41 42void setup() { 43 Serial.begin(9600); 44} 45 46void loop() { 47 int customKey = customKeypad.getKey(); 48 49 if (customKey == '1') { 50 tone(buzzer, NOTE_C, 200); 51 } 52 if (customKey == '2') { 53 tone(buzzer, NOTE_CS, 200); 54 } 55 if (customKey == '3') { 56 tone(buzzer, NOTE_D, 200); 57 } 58 if (customKey == '4') { 59 tone(buzzer, NOTE_E, 200); 60 } 61 if (customKey == '5') { 62 tone(buzzer, NOTE_F, 200); 63 } 64 if (customKey == '6') { 65 tone(buzzer, NOTE_FS, 200); 66 } 67 if (customKey == '7') { 68 tone(buzzer, NOTE_G, 200); 69 } 70 if (customKey == '8') { 71 tone(buzzer, NOTE_A, 200); 72 } 73 if (customKey == 'A') { 74 tone(buzzer, NOTE_B, 200); 75 } 76 if (customKey == 'B') { 77 tone(buzzer, NOTE_C2, 200); 78 } 79 if (customKey == 'C') { 80 tone(buzzer, NOTE_CS2, 200); 81 } 82 if (customKey == 'D') { 83 tone(buzzer, NOTE_D2, 200); 84 } 85 if (customKey == 'E') { 86 tone(buzzer, NOTE_E2, 200); 87 } 88 if (customKey == 'F') { 89 tone(buzzer, NOTE_F2, 200); 90 } 91 if (customKey == 'G') { 92 tone(buzzer, NOTE_FS2, 200); 93 } 94 if (customKey == 'H') { 95 tone(buzzer, NOTE_G2, 200); 96 } 97}
Keypad Music Player Code
c_cpp
1#include <Keypad.h> 2 3 4// Defines how many rows and columns there 5 are 6const byte ROWS = 4; 7const byte COLS = 4; 8 9// Define name of keys 10char 11 hexaKeys[ROWS][COLS] = { 12 {'1', '2', '3', '4'}, 13 {'5', '6', '7', '8'}, 14 15 {'A', 'B', 'C', 'D'}, 16 {'E', 'F', 'G', 'H'} 17}; 18 19byte colPins[ROWS] 20 = {9, 8, 7, 6}; 21byte rowPins[COLS] = {5, 4, 3, 2}; 22 23Keypad customKeypad 24 = Keypad(makeKeymap(hexaKeys), colPins, rowPins, ROWS, COLS); 25 26// Define notes 27#define 28 NOTE_C 523 29#define NOTE_CS 554 30#define NOTE_D 587 31#define NOTE_E 659 32#define 33 NOTE_F 698 34#define NOTE_FS 740 35#define NOTE_G 784 36#define NOTE_A 880 37#define 38 NOTE_B 988 39#define NOTE_C2 1047 40#define NOTE_CS2 1109 41#define NOTE_D2 42 1175 43#define NOTE_E2 1319 44#define NOTE_F2 1397 45#define NOTE_FS2 1480 46#define 47 NOTE_G2 1568 48 49// Change this depending on your pin on the Arduino 50const 51 int buzzer = 11; 52 53void setup() { 54 Serial.begin(9600); 55} 56 57void 58 loop() { 59 int customKey = customKeypad.getKey(); 60 61 if (customKey == '1') 62 { 63 tone(buzzer, NOTE_C, 200); 64 } 65 if (customKey == '2') { 66 tone(buzzer, 67 NOTE_CS, 200); 68 } 69 if (customKey == '3') { 70 tone(buzzer, NOTE_D, 200); 71 72 } 73 if (customKey == '4') { 74 tone(buzzer, NOTE_E, 200); 75 } 76 if 77 (customKey == '5') { 78 tone(buzzer, NOTE_F, 200); 79 } 80 if (customKey 81 == '6') { 82 tone(buzzer, NOTE_FS, 200); 83 } 84 if (customKey == '7') { 85 86 tone(buzzer, NOTE_G, 200); 87 } 88 if (customKey == '8') { 89 tone(buzzer, 90 NOTE_A, 200); 91 } 92 if (customKey == 'A') { 93 tone(buzzer, NOTE_B, 200); 94 95 } 96 if (customKey == 'B') { 97 tone(buzzer, NOTE_C2, 200); 98 } 99 if 100 (customKey == 'C') { 101 tone(buzzer, NOTE_CS2, 200); 102 } 103 if (customKey 104 == 'D') { 105 tone(buzzer, NOTE_D2, 200); 106 } 107 if (customKey == 'E') { 108 109 tone(buzzer, NOTE_E2, 200); 110 } 111 if (customKey == 'F') { 112 tone(buzzer, 113 NOTE_F2, 200); 114 } 115 if (customKey == 'G') { 116 tone(buzzer, NOTE_FS2, 117 200); 118 } 119 if (customKey == 'H') { 120 tone(buzzer, NOTE_G2, 200); 121 122 } 123}
Downloadable files
4x4 Keypad Music Player
4x4 Keypad Music Player
4x4 Keypad Music Player
4x4 Keypad Music Player
keypad_music_bb_ddlZnFton3.png
keypad_music_bb_ddlZnFton3.png

Comments
Only logged in users can leave comments