From 02b1748bdd47d235ec1246c2f6aa6c76d5078bf1 Mon Sep 17 00:00:00 2001 From: joshnishikawa Date: Fri, 11 Feb 2022 12:07:09 +0900 Subject: [PATCH] fixed PER_DETENT (again) --- README.md | 5 ++++- examples/MIDIenc/MIDIenc.ino | 2 +- library.properties | 2 +- src/MIDIenc.cpp | 18 +++++++++++++----- 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index eec76d5..ae3f590 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# MIDIcontroller 2.4.2 +# MIDIcontroller 2.4.3 ### A library for creating Teensy MIDI controllers. ###### by Josh Nishikawa @@ -16,6 +16,9 @@ ___ ___ ### VERSION LOG: +2.4.3 +- Fixed it again (hopefully without breaking anything else this time). + 2.4.2 - Fixed a bug preventing PER_DETENT from working on encoders. diff --git a/examples/MIDIenc/MIDIenc.ino b/examples/MIDIenc/MIDIenc.ino index a2e9edd..d8fc692 100644 --- a/examples/MIDIenc/MIDIenc.ino +++ b/examples/MIDIenc/MIDIenc.ino @@ -11,7 +11,7 @@ const int ledPin = 13; // Set an LED to show the state of the switch. // You can also add min AND max output // and/or PER_DETENT as a final argument. // PER_DETENT increases or decreases the CC value once per detent. (on detented quadratic encoders) -MIDIenc myEnc(encPinA, encPinB, 24); +MIDIenc myEnc(encPinA, encPinB, 24, PER_DETENT); MIDIbutton myButton(buttonPin, 25, LATCH); // CC #25 in latch mode diff --git a/library.properties b/library.properties index 4a054d5..3d7de0d 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=MIDIcontroller -version=2.4.2 +version=2.4.3 author=Josh Nishikawa maintainer=Josh Nishikawa sentence=A library for creating Teensy MIDI controllers. diff --git a/src/MIDIenc.cpp b/src/MIDIenc.cpp index f61398c..7fbbb69 100644 --- a/src/MIDIenc.cpp +++ b/src/MIDIenc.cpp @@ -48,15 +48,23 @@ MIDIenc::~MIDIenc(){ int MIDIenc::read(){ int newValue = -1; int incdec = myKnob->read(); - if(incdec >= detentOrValue && value < outHi){ - newValue = value + 1; + + if (incdec >= detentOrValue){ + if (value < outHi){ + newValue = value + 1; + } myKnob->write(0); } - else if (incdec <= -detentOrValue && value > outLo){ - newValue = value - 1; + else if (incdec <= -detentOrValue){ + if (value > outLo){ + newValue = value - 1; + } myKnob->write(0); } - else{newValue = -1;} + else{ + newValue = -1; + } + return newValue; };