added encoder acceleration. still needs fine-tuning

This commit is contained in:
Oleksiy
2025-04-06 22:51:57 +03:00
parent 395fa1ef1f
commit 8116b1182a
3 changed files with 160 additions and 46 deletions

View File

@ -1,5 +1,4 @@
#include <Wire.h>
//#include <RotaryEncoder.h>
#include <FlexiTimer2.h>
#include <EEPROM.h>
#include <U8g2lib.h>
@ -51,7 +50,7 @@ bool rotateScreen = true;
uint16_t CV1Calibration = 512;
uint16_t CV2Calibration = 512;
bool showDone = false;
const int subDivs[20] = { -24, -12, -8, -6, -4, -3, -2, 1, 2, 3, 4, 5, 6, 7, 8, 16, 24, 32, 64, 128 }; //positive - divide, negative - multiply, 0 - off
@ -128,6 +127,7 @@ byte menuItem = 0;
bool menuItemSelected = false;
byte lastMenuItem = 3;
byte displayScreen = 0; //0 - main, 1 - sequencer, 2 - settings
bool showDone = false;
bool playBtnPushed = false;
bool shiftBtnPushed = false;
@ -151,7 +151,6 @@ int extTriggerCount;
//unsigned long lastInteractionTime; // used for display timeout
U8G2_SSD1306_128X64_NONAME_2_HW_I2C u8g2(U8G2_R2, SCL, SDA, U8X8_PIN_NONE);
//RotaryEncoder encoder(ENC_D1_PIN, ENC_D2_PIN, RotaryEncoder::LatchMode::TWO03);
//Font
const PROGMEM uint8_t velvetscreen[437] U8G2_FONT_SECTION("velvetscreen") =
@ -210,6 +209,15 @@ void setup() {
pinMode(clockOutPin, OUTPUT);
pinMode(ENC_D1_PIN, INPUT_PULLUP);
pinMode(ENC_D2_PIN, INPUT_PULLUP);
//Enabling PinChange Interrupts for the encoder
//pins 17 (PC3/PCINT11) and 4 (PD4/PCINT20), ports C and D
PCICR |= 0b00000110;
PCMSK1 |= 0b00001000;
PCMSK2 |= 0b00010000;
loadState();
u8g2.begin();
@ -222,14 +230,6 @@ void setup() {
resetClocks();
pinMode(ENC_D1_PIN, INPUT_PULLUP);
pinMode(ENC_D2_PIN, INPUT_PULLUP);
//Enabling PinChange Interrupts for the encoder
//pins 17 (PC3/PCINT11) and 4 (PD4/PCINT20), ports C and D
PCICR |= 0b00000110;
PCMSK1 |= 0b00001000;
PCMSK2 |= 0b00010000;
FlexiTimer2::set(1, 1.0 / 10000, clock); // 1.0/1000 = 1ms period. If other than 1ms calculateBPMTiming() might need tweaking
FlexiTimer2::start();
}
@ -254,6 +254,8 @@ 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;
void checkEncoderStatus() {
bool pin1Status = digitalRead(ENC_D1_PIN);
bool pin2Status = digitalRead(ENC_D2_PIN);