#include #include #include "MIDIUSB.h" #define CC_ONE_PIN 14 #define LED_PIN 8 #define BTN_PIN 5 EwmaT filter(10, 100); int ccOneVal = 0; int ccNumOffset = 0; int btnVal; void setup() { Serial.begin(115200); pinMode(LED_PIN, OUTPUT); pinMode(BTN_PIN, INPUT_PULLUP); } // First parameter is the event type (0x0B = control change). // Second parameter is the event type, combined with the channel. // Third parameter is the control number number (0-119). // Fourth parameter is the control value (0-127). void controlChange(uint8_t channel, uint8_t control, uint8_t value) { midiEventPacket_t event = {0x0B, 0xB0 | channel, control, value}; MidiUSB.sendMIDI(event); } void loop() { ccOneVal = analogRead(CC_ONE_PIN); btnVal = digitalRead(BTN_PIN); if(btnVal == LOW){ analogWrite(LED_PIN, 150); ccNumOffset = 10; }else{ analogWrite(LED_PIN, 0); ccNumOffset = 0; } int ccOneValFiltered = filter.filter(ccOneVal); Serial.print(0); Serial.print(','); Serial.print(1023); Serial.print(','); Serial.print(ccOneVal); Serial.print(','); Serial.println(ccOneValFiltered); uint8_t ccOneOutput = map(ccOneValFiltered, 0, 1023, 0, 127); controlChange(0, 10 + ccNumOffset, ccOneOutput); // Set the value of controller 10 on channel 0 to 65 MidiUSB.flush(); delay(10); }