stripped encoder to barebones, added midi start for external clock (still needs midi stop though)

This commit is contained in:
Oleksiy
2025-04-14 00:06:44 +03:00
parent 2a5f9d8304
commit ecb1f0e525
2 changed files with 14 additions and 20 deletions

View File

@ -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

View File

@ -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) {