Last active
July 21, 2018 00:54
-
-
Save jonmoshier/4584593fa5e16ad0f1935e607bb7ffbb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
float bend; | |
float pitch_value; | |
float divider = 38; | |
int vcaPin = 10; | |
int current; | |
void setup() { | |
usbMIDI.setHandleNoteOff(OnNoteOff); | |
usbMIDI.setHandleNoteOn(OnNoteOn); | |
usbMIDI.setHandleVelocityChange(OnVelocityChange); | |
usbMIDI.setHandleControlChange(OnControlChange); | |
usbMIDI.setHandleProgramChange(OnProgramChange); | |
usbMIDI.setHandleAfterTouch(OnAfterTouch); | |
usbMIDI.setHandlePitchChange(OnPitchChange); | |
analogWriteResolution(12); | |
pinMode(vcaPin, OUTPUT); | |
} | |
void loop() { | |
usbMIDI.read(); | |
} | |
void OnNoteOn(byte channel, byte note, byte velocity) { | |
current = note; | |
float pitch_value = constrain(note, 60, 99); | |
float velocity_value = constrain(velocity, 0, 255); | |
analogWrite(A14, ((pitch_value - 60.0) / divider) * 4095.0); | |
analogWrite(vcaPin, velocity_value); | |
} | |
void OnNoteOff(byte channel, byte note, byte velocity) { | |
if (note != current) { return; } | |
float velocity_value = constrain(velocity, 0, 255); | |
analogWrite(vcaPin, velocity_value); | |
} | |
void OnVelocityChange(byte channel, byte note, byte velocity) { | |
float velocity_value = constrain(velocity, 0, 255); | |
analogWrite(vcaPin, velocity_value); | |
} | |
void OnPitchChange(byte channel, int pitch) { | |
bend = map(pitch, 0, 16383, -12.0, 12.0); | |
analogWrite(vcaPin, ((pitch_value + bend - 60.0) / divider) * 4095.0); | |
} | |
void OnControlChange(byte channel, byte control, byte value) { } | |
void OnProgramChange(byte channel, byte program) { } | |
void OnAfterTouch(byte channel, byte pressure) { } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment