Hi everyone!
Hope all of you are ok =)
Soooo....dont know where to start. Well, i ve been trying to finish a metronome for about 3 days now, and have encountered with some issues with the timing tasks.
This metronome involves three buttons, a potenciometer, and obviously, a speaker.
1.- I want the buttons to acomplish the following:
a. Tap the tempo feature.
b. Number of notes for the time signature.
c. Dont know yet but maybe i´ll integrate a stop/start function.
I have no problems with b, the thing is, i´ve found me quite annoyed by the time setups and/or compatibility issues between delay() and millis() functions. Frankly, i feel so dumb hahaha.
I´ve manage to obtain the BPM, and thus, to start the endlesly beeping sound.
Everything ok to that point.
Now, with the tap feature...i have no idea how to do it. Can you guys help me? XP
I want to calculate the time, in miliseconds, from one push of a button to the second push. Like an "A to B" situation. Just wanna know that, and maybe from there, discover how to do it with three or four pushes.
Thats the general idea. Press the button once and start counting, press a second time (the same button) and stop the timer (or leave a mark). Calculate the difference in miliseconds, and give that number to the BPM factor.
I hope i´ve made myself clear enough so you guys can help me, my english is very rusty. Then again, if you guys can give me a clue at least of what i can do, it´ll be either way apreciated.
Thanks a lot Guys.
Have a nice day!
p.d : My code for now (pls, still a noob, be gentle hahah).
const int speaker = 8;
const int tapTempo = 7; //Tap tempo function
int notespc = 6; //Number of notes in a compass (2,3,4,5,6,7,8,9,10,11,12)
const int accent = 440; //Frecuency of the accent note (first measure)
const int noAccent = 330; //Notes after the accent
const int manualTempo = A0; //Potenciometer to set tempo
int beat = 1; //Beats starts at "1" Modified through time
int notes = 3;
void setup() {
Serial.begin(9600);
pinMode(speaker, OUTPUT);
pinMode(tapTempo, INPUT);
pinMode(notes, INPUT);
}
void loop() {
VariableTimedAction::updateActions();
buttons();
metronome();
Serial.println(notes);
}
void metronome(){
int potValue = map(analogRead(manualTempo), 0, 1023, 40, 300);
Serial.println(potValue);
int BPM = (60000/potValue);
Serial.println(BPM);
if(beat == 1){
tone(speaker, accent, 50);
}
else {
tone(speaker, noAccent, 50);
}
delay(BPM);
noTone(speaker);
if(beat > notes){
beat = 1;
}
else {
(beat++);
}
}
void buttons(){
int curNotes;
curNotes = digitalRead(notespc);
if(curNotes == HIGH){
notes++;
} else {
notes = notes;
}
if(notes == 13){
notes = 1;
delay(10);
}
}