Hi guys, I'm new to arduino. I built an arduino piano using the digital inputs as my push button switches. Now, my problem is, how can i record what I've been playing on the arduino piano without any shields. Somebody told me that I could do it by recording the key pressed and add a timer so it could be determined how long the was pressed. The problem is, I don't know how to put it into codes. Please help me. Please.. Thanks in advance!
Here's the code:
int inputPin1 = 13;
int inputPin2 = 12;
int inputPin3 = 11;
int inputPin4 = 10;
int inputPin5 = 9;
int inputPin6 = 8;
int inputPin7 = 7;
int inputPin8 = 6;
int inputPin9 = 5;
int inputPin10 = 4;
int inputPin11 = 3;
int inputPin12 = 2;
int speakerPin = A0;
int val = 0;
int length = 1; // the number of notes
char notes[] = { 'c', 'C', 'd', 'D', 'e', 'f', 'F', 'g', 'G', 'a', 'A', 'b' }; // a space represents a rest
int beats[] = { 1 };
int tempo = 300;
void playTone(int tone, int duration) {
for (long i = 0; i < duration * 1000L; i += tone * 2) {
digitalWrite(speakerPin, HIGH);
delayMicroseconds(tone);
digitalWrite(speakerPin, LOW);
delayMicroseconds(tone);
}
}
void playNote(char note, int duration) {
char names[] = { 'c', 'C', 'd', 'D', 'e', 'f', 'F', 'g', 'G', 'a', 'A', 'b' };
int tones[] = { 1911, 1804, 1702, 1607, 1517, 1432, 1351, 1276, 1204, 1136, 1073, 1012 };
// play the tone corresponding to the note name
for (int i = 0; i < 12; i++) {
if (names == note) { *
_ playTone(tones, duration);_
_ }_
_ }_
_}_
void setup() {
_ pinMode(speakerPin, OUTPUT);_
_ pinMode(inputPin1, INPUT);_
_ pinMode(inputPin2, INPUT);_
_ pinMode(inputPin3, INPUT);_
_ pinMode(inputPin4, INPUT);_
_ pinMode(inputPin5, INPUT);_
_ pinMode(inputPin6, INPUT);_
_ pinMode(inputPin7, INPUT);_
_ pinMode(inputPin8, INPUT);_
_ pinMode(inputPin9, INPUT);_
_ pinMode(inputPin10, INPUT);_
_ pinMode(inputPin11, INPUT);_
_ pinMode(inputPin12, INPUT);_
_}_
void loop() {
_ if (digitalRead(inputPin1) == HIGH) {_
_ playNote(notes[0], 300);_
_ } else if (digitalRead(inputPin2) == HIGH) {_
_ playNote(notes[1], 300);_
_ } else if (digitalRead(inputPin3) == HIGH) {_
_ playNote(notes[2], 300);_
_ } else if (digitalRead(inputPin4) == HIGH) {_
_ playNote(notes[3], 300);_
_ } else if (digitalRead(inputPin5) == HIGH) {_
_ playNote(notes[4], 300);_
_ } else if (digitalRead(inputPin6) == HIGH) {_
_ playNote(notes[5], 300);_
_ } else if (digitalRead(inputPin7) == HIGH) {_
_ playNote(notes[6], 300);_
_ } else if (digitalRead(inputPin8) == HIGH) {_
_ playNote(notes[7], 300);_
_ } else if (digitalRead(inputPin9) == HIGH) {_
_ playNote(notes[8], 300);_
_ } else if (digitalRead(inputPin10) == HIGH) {_
_ playNote(notes[9], 300);_
_ } else if (digitalRead(inputPin11) == HIGH) {_
_ playNote(notes[10], 300);_
_ } else if (digitalRead(inputPin12) == HIGH) {_
_ playNote(notes[11], 300);_
_ } else {_
_ digitalWrite(speakerPin, LOW);_
_ }_
_}*_