I have the code for my keypad
include
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);
void setup(){
Serial.begin(9600);
}
void loop(){
char customKey = customKeypad.getKey();
if (customKey){
Serial.println(customKey);
}
}
I want to combine the keypad code with the sample code from the Arduino starter kit book project number 7.
/*
Keyboard
Plays a pitch that changes based on a changing
input circuit:
* 3 pushbuttons from +5V to analog in 0 through
3
* 3 10K resistors from analog in 0 through 3 to
ground
* 8-ohm speaker on digital pin 8
*/
int pos = 0;
void setup()
{
pinMode(A0, INPUT);
pinMode(8, OUTPUT);
pinMode(A1, INPUT);
pinMode(A2, INPUT);
}
void loop()
{
// if button press on A0 is detected
if (digitalRead(A0) == HIGH) {
tone(8, 440, 100); // play tone 57 (A4 = 440 Hz)
}
// if button press on A1 is detected
if (digitalRead(A1) == HIGH) {
tone(8, 494, 100); // play tone 59 (B4 = 494 Hz)
}
// if button press on A0 is detected
if (digitalRead(A2) == HIGH) {
tone(8, 523, 100); // play tone 60 (C5 = 523 Hz)
}
delay(10); // Delay a little bit to improve simulation performance
}
I want to combine the two codes so that the keypad plays a tone;
when a button is pressed on the keypad ( for example, button 1 ), play tone __ = ___ Hz
How would I do this? If you need a better explanation, contact me on facebook = https://www.facebook.com/profile.php?id=100014328558284