#include #include #include #include "TrackerTypes.h" #include "MidiDriver.h" #include "UIManager.h" #include "config.h" #include "UIThread.h" #include "PlaybackThread.h" #include "SharedState.h" // Encoder State static uint8_t prevNextCode = 0; static uint16_t store = 0; // --- ENCODER INTERRUPT --- // Robust Rotary Encoder reading void readEncoder() { static int8_t rot_enc_table[] = {0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0}; prevNextCode <<= 2; if (digitalRead(ENC_DT)) prevNextCode |= 0x02; if (digitalRead(ENC_CLK)) prevNextCode |= 0x01; prevNextCode &= 0x0f; // If valid state if (rot_enc_table[prevNextCode]) { store <<= 4; store |= prevNextCode; if ((store & 0xff) == 0x2b) encoderDelta--; if ((store & 0xff) == 0x17) encoderDelta++; } } void setup() { Serial.begin(115200); // Use random ADC noise for seed delay(5000); Serial.println(F("Starting.")); // 1. Setup Encoder pinMode(ENC_CLK, INPUT_PULLUP); pinMode(ENC_DT, INPUT_PULLUP); pinMode(ENC_SW, INPUT_PULLUP); attachInterrupt(digitalPinToInterrupt(ENC_CLK), readEncoder, CHANGE); attachInterrupt(digitalPinToInterrupt(ENC_DT), readEncoder, CHANGE); ui.begin(); midi.begin(); // 5. Init Sequence randomSeed(micros()); EEPROM.begin(512); if (!loadSequence()) { generateRandomScale(); for(int i=0; i