From 2f4c42c33fea79a6b1c03b1cb5123ccd4ff8fa76 Mon Sep 17 00:00:00 2001 From: Oleksiy Date: Sun, 6 Sep 2026 14:21:40 +0300 Subject: [PATCH] Added MIDI Channel setup mode, added disconnectDigitalIn to analogue inputs according to Mozzi docs --- .gitignore | 1 + FLMNG/FLMNG.ino | 73 +++++++++++++++++++++++++++++++++++++++++++++++-- FLMNG/config.h | 1 - 3 files changed, 72 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 1addd27..13f531f 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ */build/arduino.avr.nano +.DS_Store diff --git a/FLMNG/FLMNG.ino b/FLMNG/FLMNG.ino index 54cf6bd..4266b8e 100644 --- a/FLMNG/FLMNG.ino +++ b/FLMNG/FLMNG.ino @@ -27,6 +27,7 @@ #include #include #include +#include #include "config.h" IntMap kMapCarrierNote( 0, 4095, 24 * pitchSubSteps, 84 * pitchSubSteps ); @@ -53,6 +54,8 @@ bool MIDINotePlaying; bool gateIsHigh = false; float carrierFreq; long FMIntensity; // carries control info from updateControl to updateAudio +byte MIDIChannel; +byte memCode = "a"; void MIDINoteOn(byte channel, byte note, byte velocity) { carrierFreq = mtof((int) note); @@ -77,12 +80,78 @@ long softClip(long input) { } } -void setup(){ +void setup() { pinMode(LED, OUTPUT); pinMode(GateIn, INPUT_PULLUP); pinMode(EnvSwitch, INPUT_PULLUP); pinMode(DroneSwitch, INPUT_PULLUP); + //MIDI Channel setup + if(!digitalRead(GateIn)) { //&& !digitalRead(DroneSwitch) && !digitalRead(EnvSwitch)) { //MIDI setup mode, first knob you rotate = MIDI channel + int knob1Orig = analogRead(Knob1); + int knob2Orig = analogRead(Knob2); + int knob3Orig = analogRead(Knob3); + int knob4Orig = analogRead(Knob4); + int knobAOrig = analogRead(KnobA); + int knobDROrig = analogRead(KnobDR); + int knobSOrig = analogRead(KnobS); + int threshhold = 50; //To reduce noise from the input, needs testing and fine-tuning + while(true) { + if(abs(analogRead(Knob1) - knob1Orig) > threshhold) { + MIDIChannel = 1; + break; + } else if (abs(analogRead(Knob2) - knob2Orig) > threshhold) { + MIDIChannel = 2; + break; + } else if (abs(analogRead(Knob3) - knob3Orig) > threshhold) { + MIDIChannel = 3; + break; + } else if (abs(analogRead(Knob4) - knob4Orig) > threshhold) { + MIDIChannel = 4; + break; + } else if (abs(analogRead(KnobA) - knobAOrig) > threshhold) { + MIDIChannel = 5; + break; + } else if (abs(analogRead(KnobDR) - knobDROrig) > threshhold) { + MIDIChannel = 6; + break; + } else if (abs(analogRead(KnobS) - knobSOrig) > threshhold) { + MIDIChannel = 7; + break; + } + digitalWrite(LED, HIGH); //slow blinking to indicate the setup mode + delay(500); + digitalWrite(LED, LOW); + delay(500); + } + EEPROM.write(0, MIDIChannel); + EEPROM.write(1023, memCode); + digitalWrite(LED, LOW); + delay(150); + for(int i = 0; i < MIDIChannel; i ++) { //fast blink to indicate saved MIDI channel + digitalWrite(LED, HIGH); + delay(150); + digitalWrite(LED, LOW); + delay(150); + } + delay(500); + } else if (EEPROM.read(1023) == memCode) { + MIDIChannel = EEPROM.read(0); + } else { //Save default MIDI Channel to EEPROM if it wasn't set + MIDIChannel = 1; //channel 1 by default + EEPROM.write(0, MIDIChannel); + EEPROM.write(1023, memCode); + } + + disconnectDigitalIn(Knob1); + disconnectDigitalIn(Knob2); + disconnectDigitalIn(Knob3); + disconnectDigitalIn(Knob4); + disconnectDigitalIn(KnobA); + disconnectDigitalIn(KnobDR); + disconnectDigitalIn(KnobS); + disconnectDigitalIn(CVIn); + MIDI.setHandleNoteOn(MIDINoteOn); MIDI.setHandleNoteOff(MIDINoteOff); @@ -92,7 +161,7 @@ void setup(){ MIDI.setHandleContinue(nullptr); MIDI.setHandleControlChange(nullptr); - MIDI.begin(MIDI_CHANNEL); + MIDI.begin(MIDIChannel); MIDI.turnThruOff(); startMozzi(); diff --git a/FLMNG/config.h b/FLMNG/config.h index 68c2f9c..08dc1ea 100644 --- a/FLMNG/config.h +++ b/FLMNG/config.h @@ -2,7 +2,6 @@ const int pitchSubSteps = 16; //set how many steps are there between semitones. set to 1 to quantize to semitones const int driveAmount = 350; const bool oversamplingEnabled = false; //makes V/OCT tracking more precise, but adds a little portamento -#define MIDI_CHANNEL 2 //MIDI_CHANNEL_OMNI #define MOZZI_CONTROL_RATE 1024 //Hardware Definitions