Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions src/ArduinoTapTempo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,24 @@ float ArduinoTapTempo::getBPM()
return 60000.0 / beatLengthMS;
}

float ArduinoTapTempo::setBPM(float bpm)
void ArduinoTapTempo::setBPM(float bpm)
{
beatLengthMS = 60000 / bpm;
setBeatLength(60000 / bpm);
}

void ArduinoTapTempo::setBeatLength(unsigned long lengthMS)
{
if (lengthMS > maxBeatLengthMS)
{
beatLengthMS = maxBeatLengthMS;
}
else if (lengthMS < minBeatLengthMS) {
beatLengthMS = minBeatLengthMS;
}
else
{
beatLengthMS = lengthMS;
}
}

bool ArduinoTapTempo::onBeat()
Expand Down
3 changes: 2 additions & 1 deletion src/ArduinoTapTempo.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,13 @@ class ArduinoTapTempo
bool isChainActive(); // returns true if the current tap chain is still accepting new taps to fine tune the tempo
bool isChainActive(unsigned long ms); // returns true if the current tap chain is still accepting new taps to fine tune the tempo
float getBPM(); // returns the number of beats per minute
float setBPM(float bpm); // sets the number of beats per minute
void setBPM(float bpm); // sets the number of beats per minute
float beatProgress(); // returns a float from 0.0 to 1.0 indicating the percent through the current beat
void resetTapChain(); // resets the current chain of taps and sets the start of the bar to the current time
void resetTapChain(unsigned long ms); // resets the current chain of taps and sets the start of the bar to the current time

inline unsigned long getBeatLength() { return beatLengthMS; } // returns the length of the beat in milliseconds
void setBeatLength(unsigned long lengthMS); // sets the length of the beat in MS directly
inline unsigned long getLastTapTime() { return lastTapMS; } // returns the time of the last tap in milliseconds since the program started

void update(bool buttonDown); // call this each time you read your button state, accepts a boolean indicating if the button is down
Expand Down