From ecb1f0e525e3f66c45964903788787d2597dba66 Mon Sep 17 00:00:00 2001 From: Oleksiy Date: Mon, 14 Apr 2025 00:06:44 +0300 Subject: [PATCH] stripped encoder to barebones, added midi start for external clock (still needs midi stop though) --- Software/Gravity/Gravity.ino | 26 +++++++++++--------------- Software/Gravity/Interactions.ino | 8 +++----- 2 files changed, 14 insertions(+), 20 deletions(-) diff --git a/Software/Gravity/Gravity.ino b/Software/Gravity/Gravity.ino index 77b2245..6c07fea 100644 --- a/Software/Gravity/Gravity.ino +++ b/Software/Gravity/Gravity.ino @@ -250,17 +250,15 @@ ISR (PCINT2_vect) { } uint8_t encoderStatus; -uint32_t encoderCheckTime = 0; -uint32_t encoderTimeBetweenPulses = 0; -bool encoderDirectionOld; //0 = -, 1 = +, Old because current direction can be determined by encoderChange +//uint32_t encoderCheckTime = 0; +//uint32_t encoderTimeBetweenPulses = 0; +//bool encoderDirectionOld; //0 = -, 1 = +, Old because current direction can be determined by encoderChange int8_t encoderChange = 0; -uint8_t encoderBurstCount = 0; +//uint8_t encoderBurstCount = 0; void checkEncoderStatus() { - bool pin1Status = digitalRead(ENC_D1_PIN); - bool pin2Status = digitalRead(ENC_D2_PIN); - uint8_t newStatus = (pin1Status << 1) | pin2Status; - switch(encoderStatus) { // encoderStatus & 0b00000011 - to check only 2 last bits + uint8_t newStatus = (digitalRead(ENC_D1_PIN) << 1) | digitalRead(ENC_D2_PIN); + switch(encoderStatus) { case 0b00: if (newStatus == 0b01) { encoderChange++; @@ -290,13 +288,11 @@ void checkEncoderStatus() { } break; } - //encoderStatus = (encoderStatus << 2); //previous status is now stored in bits 2 and 3 - encoderStatus = bitWrite(encoderStatus, 1, pin1Status); - encoderStatus = bitWrite(encoderStatus, 0, pin2Status); //This can probably be more optimizied with bit logic + encoderStatus = newStatus; - uint32_t currentTime = millis(); - encoderTimeBetweenPulses = currentTime - encoderCheckTime; - encoderCheckTime = currentTime; + //uint32_t currentTime = millis(); + //encoderTimeBetweenPulses = currentTime - encoderCheckTime; + //encoderCheckTime = currentTime; } void sendMIDIClock() { @@ -391,8 +387,8 @@ void externalClock() { //reset cycles if there were no pulses for a while if ((newExtPulseTime - lastExtPulseTime) > 125) { //125ms is 20bpm - resetClocks(); + sendMIDIStart(); } tickCount = 0; //to make things happen in the main clock function diff --git a/Software/Gravity/Interactions.ino b/Software/Gravity/Interactions.ino index 12691ce..424ec8f 100644 --- a/Software/Gravity/Interactions.ino +++ b/Software/Gravity/Interactions.ino @@ -99,14 +99,14 @@ void checkInputs() { encoderDirectionOld = (encoderChange > 0);*/ //encoder acceleration - if (encoderTimeBetweenPulses < 15) { // <-- + /*if (encoderTimeBetweenPulses < 15) { // <-- encoderBurstCount++; } else { encoderBurstCount = 0; } if (encoderBurstCount > 3) { // <-- encoderChange = encoderChange * 3; // <-- The three params need to be finetuned to feel natural - } + }*/ if (displayScreen == 0) { byte channelCV; @@ -169,9 +169,7 @@ void checkInputs() { } else if (((!insideTab && shiftBtnPushed) || (insideTab && menuItem == 0 && (menuItemSelected || shiftBtnPushed))) - && displayTab != 0 // things to try: - // count "burst" changes and apply acceleration (test the period between ticks in a new sketch) - + && displayTab != 0 && channels[displayTab - 1].mode == 2) { //Change SEQ pattern channels[displayTab - 1].seqPattern = channels[displayTab - 1].seqPattern + encoderChange; if (channels[displayTab - 1].seqPattern > 100) {