Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions Potentiometer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,24 @@ void Potentiometer::read(){

if(mapped){
tempRead=constrain(analogRead(pin),inMin,inMax);
tempRead=map(tempRead,inMin,inMax,0,127);

/* Need to maintain analog resolution for the next
'if' statement but leaving out the upper and
lower limits prevents messages outside the MIDI range*/
tempRead=map(tempRead,inMin,inMax,7,1015);
}
else
tempRead=map(analogRead(pin), 0, 1023, 0, 127);

if (tempRead!=lastValue) { //value changed
midiCC(tempRead, lastValue);
}
lastValue=tempRead;
tempRead=analogRead(pin);

/*1 - Split the analog signal into blocks of 4
and every other block of four is ignored.
2 - Reduce the resolution for MIDI and compare
against the previously sent message.*/
if ((tempRead/4)%2 == 0 && tempRead/8 != lastValue){
newCC = tempRead/8;
midiCC(newCC, lastValue);
lastValue = newCC;
}
}

// read
Expand Down Expand Up @@ -149,4 +158,4 @@ void Potentiometer::midiCC(int v, int oldv) {

void Potentiometer::changeSecondary( bool s){
secondary=s;
}
}
3 changes: 2 additions & 1 deletion Potentiometer.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class Potentiometer {
int inMin, inMax;
int lastValue;
int tempRead;
int newCC;
int readValues[3];
byte pin; // pin on teensy
byte channel; // midi channel
Expand All @@ -44,4 +45,4 @@ class Potentiometer {
};
//-----------------------------------------------------------------------------------

#endif
#endif