UC3Music / MetroNemo

An open-source vibrating metronome
12 stars 2 forks source link

Get tempo via tap #3

Open L4g0 opened 6 years ago

David-Estevez commented 6 years ago

This could be done with a piezo sensor and a few diodes (to avoid damage to the Arduino). We have some piezos available in UC3Music, and I can give you some more diodes if you need them.

This is quite similar to Shiva, so if you have any doubts please ask! :smile:

MrTommyGuns commented 6 years ago

Done! ... (?) I used this library (https://github.com/dxinteractive/ArduinoTapTempo) and a button. It works when the metronome stops...

JorFru commented 6 years ago

It works ONLY if metronome is stopped? Maybe you're using global delays for metronome, so the entire board is halted all time and can't check for button presses.

El sáb., 14 abr. 2018 2:40, Tomás Criado notifications@github.com escribió:

Done! ... (?) I used this library (https://github.com/dxinteractive/ArduinoTapTempo) and a button. It works when the metronome stops...

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/UC3Music/MetroGnome/issues/3#issuecomment-381290887, or mute the thread https://github.com/notifications/unsubscribe-auth/AKgbgABp3OT82VAFi47Tp9xlhED-tzYQks5toUV6gaJpZM4TRnSx .

David-Estevez commented 6 years ago

Things to check out to solve this (proposed in our last meeting):

SerjSanchez commented 6 years ago

Little correction about @David-Estevez's last comment:

Things to check out to solve this (proposed in our last meeting):

Instead of using delay(), use millis() to keep track of the elapsed time. This way the arduino won't be blocked and you will be able to check the buttons. If the period of the tempo is 7ms (140 bpm), instead of using delay(7) to wait until the next measure, store the millis() value of the last measure and compare it to the elapsed time returned by millis():

bpm = 60/T (T in seconds)

So at 140bpm => T = 0,4285 s = 428,5 ms

So just replace the "7"s with 428. This doesn't affect the algorithms, but may cause some confusion.

David-Estevez commented 6 years ago

You are absolutely right, my bad 😅

MrTommyGuns commented 6 years ago

I did the next code in order to check the propose idea and I think that it's works well.

#define LED     10       // LED pin

unsigned long time = 0;
int bpm = 40;

void setup(){
  Serial.begin(9600);
    pinMode(LED, OUTPUT);
  time = millis();
}

void loop(){
      if (millis()-time == 6000/bpm)
    { 
       digitalWrite(LED, LOW);
    }
     if (millis()-time == (54000/bpm))
     {
         digitalWrite(LED, HIGH);
         Serial.print(bpm);
         Serial.println(" BPM Click!");

         time = millis(); // update current measure time 
    }

    // do other stuff here, such as checking the buttons

}

The next step is redesign the main part of the code and implement that in the loop ir order to test the buttons all the time.

If you see any problem or suggestion, tell me.