Created
November 3, 2015 09:59
-
-
Save ruizjme/44902fa91ae0d55ad357 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
/* | |
* MIDI Control Change | |
*/ | |
#include <MIDI.h> | |
MIDI_CREATE_DEFAULT_INSTANCE(); | |
#define potPin A0 // define peripherals | |
#define button1 2 | |
#define button2 3 | |
#define led 10 | |
int potValue = 0; | |
int volume1Prev; | |
int button1State; | |
int button2State; | |
int button1Prev = LOW; | |
int button2Prev = LOW; | |
int ledState = HIGH; | |
long time = 0; | |
long debounce = 200; | |
void setup() { | |
MIDI.begin(); | |
Serial.begin(115200); | |
pinMode(button1, INPUT); | |
pinMode(button2, INPUT); | |
pinMode(led, OUTPUT); | |
} | |
void loop() { | |
potValue = analogRead(potPin); | |
button1State = digitalRead(button1); | |
button2State = digitalRead(button2); | |
int volume1Value = map(potValue, 0, 1023, 0, 127); | |
if (button1State == HIGH && button1Prev == LOW && millis() - time > debounce) { | |
MIDI.sendControlChange(63, 127, 1); | |
time = millis(); | |
} | |
if (button2State == HIGH && button2Prev == LOW && millis() - time > debounce) { | |
MIDI.sendControlChange(62, 127, 1); | |
time = millis(); | |
} | |
if (volume1Value != volume1Prev && millis() - time > debounce) { | |
MIDI.sendControlChange(72, volume1Value, 1); | |
time = millis(); | |
} | |
volume1Prev = volume1Value; | |
button1Prev = button1State; | |
button2Prev = button2State; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment