Hello,
I'm attempting to make a sequencer with the bpm determined by the value of an encoder. Currently, the encoder is constrained to the values of 0 - 127, making a theoretical maximum 127 bpm. This is temporary, but may be contributing to the issue(?).
The problem is that, based off of the code that I'm using, the tempo/bpm is slightly more than twice as fast as it should be. When the value of "bpm" in the code below is multiplied by 2 (bpm = encoderCount * 2), it is close but still noticeably faster than the bpm that I'm comparing it to from another device.
Here is the code, without the multiplication mentioned above. Sorry about the very long case break portion. Currently the only thing that the tempo does is light up each LED in a 4x4 button matrix sequentially.
Thanks.
I'm attempting to make a sequencer with the bpm determined by the value of an encoder. Currently, the encoder is constrained to the values of 0 - 127, making a theoretical maximum 127 bpm. This is temporary, but may be contributing to the issue(?).
The problem is that, based off of the code that I'm using, the tempo/bpm is slightly more than twice as fast as it should be. When the value of "bpm" in the code below is multiplied by 2 (bpm = encoderCount * 2), it is close but still noticeably faster than the bpm that I'm comparing it to from another device.
Here is the code, without the multiplication mentioned above. Sorry about the very long case break portion. Currently the only thing that the tempo does is light up each LED in a 4x4 button matrix sequentially.
Code:
void sequencer(void) {
long bpm = encoderCount; //encoderCount is a global variable
long tempo = 1000.0 / (bpm / 60.0);
float interval = tempo / 24.0;
Serial.println(encoderCount);
unsigned long t = millis();
if ((t - lastTime) >= interval) { //lastTime is a global variable
lastTime = t;
stepSq++; //stepSq is a global variable
if (stepSq > 15) {
stepSq = 0;
}
switch (stepSq) {
case 0:
trellisoff(15);
trellison(0);
break;
case 1:
trellisoff(0);
trellison(1);
break;
case 2:
trellisoff(1);
trellison(2);
break;
case 3:
trellisoff(2);
trellison(3);
break;
case 4:
trellisoff(3);
trellison(4);
break;
case 5:
trellisoff(4);
trellison(5);
break;
case 6:
trellisoff(5);
trellison(6);
break;
case 7:
trellisoff(6);
trellison(7);
break;
case 8:
trellisoff(7);
trellison(8);
break;
case 9:
trellisoff(8);
trellison(9);
break;
case 10:
trellisoff(9);
trellison(10);
break;
case 11:
trellisoff(10);
trellison(11);
break;
case 12:
trellisoff(11);
trellison(12);
break;
case 13:
trellisoff(12);
trellison(13);
break;
case 14:
trellisoff(13);
trellison(14);
break;
case 15:
trellisoff(14);
trellison(15);
break;
}
}
}
Thanks.