diff --git a/software/GToE/GToE.ino b/software/GToE/GToE.ino index 9be0cf8..05811e4 100644 --- a/software/GToE/GToE.ino +++ b/software/GToE/GToE.ino @@ -11,13 +11,14 @@ #define PULSE_LENGTH 12 //ms (with 12 ms you can't get higher than 208bpm) #define MAXBPM 200 //250 at 24ppqn with 5ms pulse will be 50/50 square wave #define MINBPM 20 -#define SCREEN_TIMEOUT 30000 //Turn display off after 30 sec +#define SCREEN_TIMEOUT 120000 //Turn display off after 2 min -#define INPUT_PIN 2 //needs to be an interrupt pin #define ENC_BTN_PIN 14 #define ENC_D1_PIN 17 #define ENC_D2_PIN 4 #define START_STOP_BTN_PIN 5 + +#define INPUT_PIN 2 //needs to be an interrupt pin #define ANALOGUE_INPUT_1_PIN A2 #define ANALOGUE_INPUT_2_PIN A1 @@ -145,7 +146,7 @@ void loop() { display.clearDisplay(); display.display(); } - if (masterClockMode == 2) { + if (masterClockMode == 2 && tickCount > PULSE_LENGTH) { calculateBPMTiming(); } } @@ -177,7 +178,7 @@ void clock() { //EXT-B if (masterClockMode == 2) { - if (tickCount == pulsePeriod && pulseCount < (PPQN-1)) { + if (tickCount >= pulsePeriod && pulseCount < (PPQN-1)) { tickCount = 0; pulseCount++; } @@ -220,8 +221,11 @@ void externalClock() { if (!isPlaying) { isPlaying = true; } - pulseCount = 0; + if ((newExtPulseTime - lastExtPulseTime) > 3000) { //3000ms is 1/4 at 20bpm + resetClocks(); + } tickCount = 0; + pulseCount = 0; } } @@ -410,9 +414,12 @@ void checkInputs() { } //play button - if (!digitalRead(START_STOP_BTN_PIN) && !playBtnPushed && masterClockMode == 0) { - resetClocks(); - isPlaying = !isPlaying; + if (!digitalRead(START_STOP_BTN_PIN) && !playBtnPushed) { + if (masterClockMode == 0) { + calculateBPMTiming(); + resetClocks(); + isPlaying = !isPlaying; + } playBtnPushed = true; saveState(); updateScreen(); //to wake up the screen if turned off