Hi everyone, I'm going crazy because I can't really get how this library works and the offical documentation is really bad.
Basically I have a 3x4 keypad and each button has to be related to a song. You press a button and one sogn will start playing..you press another and the new song will start..seems like the simpliest thing in the world but this library is really weird to me. I realized exactly what I want without the shield and using tone() and here's the code.
Can anyone please explain like if I was a child how that musicmaker works and what are "interrupts" and why PlayFullFile() will not stop the loop()?
thanks!
#include <Keypad.h>
#include "pitches.h"
const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
char keymap[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};
byte rowPins[ROWS] = {8,7,6,5};
byte colPins[COLS] = {4,3,2};
Keypad myKeypad= Keypad(makeKeymap(keymap), rowPins, colPins, ROWS, COLS);
// notes to play, corresponding to the 3 sensors:
int notes[] = {
NOTE_C4, NOTE_D4, NOTE_E4, NOTE_F4, NOTE_G4, NOTE_A4, NOTE_B4, NOTE_C5, NOTE_D5,
};
void setup() {
}
void loop() {
char key = myKeypad.getKey();
if(key == '1')
tone(11, notes[0], 1000);
else if(key == '2')
tone(11, notes[1], 1000);
else if(key == '3')
tone(11, notes[2], 1000);
else if(key == '4')
tone(11, notes[3], 1000);
else if(key == '5')
tone(11, notes[4], 1000);
else if(key == '6')
tone(11, notes[5], 1000);
else if(key == '7')
tone(11, notes[6], 1000);
else if(key == '8')
tone(11, notes[7], 1000);
else if(key == '9')
tone(11, notes[8], 1000);
} //loop