-
|
Hi Franky: |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 4 replies
-
|
From what I can see in |
Beta Was this translation helpful? Give feedback.
-
|
Thanks for your answer but it seems to me that I have something wrong in my
original sketch of using Pitchbend with a potentiometer.
How would you do the simple sketch of using a potentiometer connected to an
analog pin to control PitchBend?
|
Beta Was this translation helpful? Give feedback.
-
|
Here's what a sketch that continuously sends PitchBend messages based on a potentiometer reading would look like: #include <MIDI.h>
// User settings
static const int pitchBendPotPin = A0;
static const int analogMaxResolutionBits = 10; // max 10, reduce to filter out noise
static const byte midiOutputChannel = 1;
// Computed settings
static const int analogFilterShift = 10 - analogMaxResolutionBits;
static const int analogMaxValue = (1 << analogMaxResolutionBits) - 1;
MIDI_CREATE_DEFAULT_INSTANCE();
void setup()
{
MIDI.begin();
}
void loop()
{
// Read the potentiometer value (10 bits of resolution)
const int rawPitchBendPotValue = analogRead(pitchBendPotPin);
// Reduce precision to filter out noise (may introduce stepping)
const int filteredPitchBend = rawPitchBendPotValue >> analogFilterShift;
// Convert the filtered value to pitch bend range
const int pitchBendValue = map(
filteredPitchBend,
0, analogMaxValue,
MIDI_PITCHBEND_MIN, MIDI_PITCHBEND_MAX
);
MIDI.sendPitchBend(pitchBendValue, midiOutputChannel);
delay(10);
} |
Beta Was this translation helpful? Give feedback.
Here's what a sketch that continuously sends PitchBend messages based on a potentiometer reading would look like: