Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get tempo via tap #3

Open
L4g0 opened this issue Apr 12, 2018 · 7 comments
Open

Get tempo via tap #3

L4g0 opened this issue Apr 12, 2018 · 7 comments
Labels
enhancement New feature or request

Comments

@L4g0
Copy link
Member

L4g0 commented Apr 12, 2018

No description provided.

@L4g0 L4g0 added the enhancement New feature or request label Apr 12, 2018
@David-Estevez
Copy link
Member

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! 😄

@MrTommyGuns
Copy link
Collaborator

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

@JorFru
Copy link
Member

JorFru commented Apr 14, 2018 via email

@David-Estevez
Copy link
Member

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():
time = millis();
while(true) // or another condition
{
   if (millis()-time = 7)
   {
       time += 7; // update current measure time  
       // blink or beep or whatever
    }
   
    // do other stuff here, such as checking the buttons
}
  • The other option, more efficient but also more complex is to use the timers to automatically keep the beat without using the cpu. Just get the period required for a given tempo and set is as the timer's period. In the same line as this, one could get the tap by using interruptions (checking the millis() for each interruption and subtracting them).

@SerjSanchez
Copy link

SerjSanchez commented Apr 29, 2018

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
Copy link
Member

You are absolutely right, my bad 😅

@MrTommyGuns
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants