would this code make sense for the task I need to complete.
when ( what ever button they pressed on the matrix keypad 3 by 4), play tone_=_Hz
here is the code:
# include <Keypad.h>
const byte ROWS = 4;
const byte COLS = 3;
char hexaKeys[ROWS][COLS] = {
{'1', '2', '3'},
{'4', '5', '6'},
{'7', '8', '9'},
{'*', '0', '#'}
};
byte rowPins[ROWS] = {5, 6, 7, 8};
byte colPins[COLS] = {2, 3, 4};
Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
int notes[] = {440,294,330,349};
void setup(){
Serial.begin(9600);
}
void loop(){
char customKey = customKeypad.getKey();
if (customKey == '1') {
tone(9, notes[0]); // play tone (A4 = 440 Hz)
}
else{
noTone(9);
}
if (customKey){
Serial.println(customKey);
}
}