stripped encoder to barebones, added midi start for external clock (still needs midi stop though)
This commit is contained in:
@ -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
|
||||
|
||||
Reference in New Issue
Block a user