Created
October 15, 2022 09:50
-
-
Save mbainrot/00c5335efd35e043b174cb2c3b21c3bf to your computer and use it in GitHub Desktop.
Quick and dirty arduino sketch yields an 8 channel MIDI CC controller for cheap.
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
#include <MIDI.h> | |
#define STROBE 5 | |
#define DATA 6 | |
#define CLK 7 | |
#define RTRN A0 | |
#define MIDI_IN 2 | |
#define MIDI_OUT 3 | |
#define VCV_MODE 4 | |
/////// MIDI CODE | |
#include <SoftwareSerial.h> | |
using Transport = MIDI_NAMESPACE::SerialMIDI<SoftwareSerial>; | |
int rxPin = 18; | |
int txPin = 19; | |
SoftwareSerial mySerial = SoftwareSerial(MIDI_IN, MIDI_OUT); | |
Transport serialMIDI(mySerial); | |
MIDI_NAMESPACE::MidiInterface<Transport> MIDI((Transport&)serialMIDI); | |
////// | |
byte addr = 99; | |
word chval[8]; | |
word deadband = 5; | |
//byte sr_addr[] = {1, 2, 4, 8, 16, 32, 64, 128}; | |
byte sr_addr[] = {8, 4, 2, 1, 128, 64, 32, 16}; | |
byte midi_ch_map[] = {1, 2, 3, 4, 5, 6, 7, 8}; | |
void setup() { | |
// put your setup code here, to run once: | |
pinMode(STROBE, OUTPUT); | |
pinMode(DATA, OUTPUT); | |
pinMode(CLK, OUTPUT); | |
pinMode(RTRN, INPUT); | |
pinMode(VCV_MODE, INPUT_PULLUP); | |
Serial.begin(115200); | |
digitalWrite(STROBE, HIGH); | |
MIDI.begin(addr); | |
} | |
unsigned long ts; | |
void loop() { | |
// put your main code here, to run repeatedly: | |
MIDI.read(); | |
if(millis() > ts) | |
{ | |
ts = millis()+50; | |
for(byte x = 0; x < 8; x++) | |
{ | |
digitalWrite(STROBE, LOW); | |
shiftOut(DATA, CLK, MSBFIRST, sr_addr[x]); | |
digitalWrite(STROBE, HIGH); | |
delay(5); | |
word tmp = analogRead(RTRN); | |
if( | |
( | |
chval[x] >= (tmp + deadband) || | |
chval[x] <= (tmp - deadband) | |
) | |
&& (tmp != 0 || (tmp == 0 && chval[x] != 0)) | |
) | |
{ | |
// send midi message | |
byte midival = map(tmp, 0, 974, 0, 127); | |
Serial.print(millis()); | |
Serial.print(": CH "); | |
Serial.print(x); | |
Serial.print(" = "); | |
Serial.print(tmp); | |
Serial.print(" ala "); | |
Serial.println(midival); | |
//MIDI.sendControlChange(80+midi_ch_map[x], midival, midi_ch_map[x]); | |
if(digitalRead(VCV_MODE) == HIGH) | |
MIDI.sendControlChange(80, midival, midi_ch_map[x]); | |
else | |
MIDI.sendControlChange(80 + midi_ch_map[x], midival, 1); | |
} | |
chval[x] = tmp; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note that it uses shift register and diodes so I can daisy chain a small truck load of pots onto a single analogue in.
Also make sure sr_addr matches up your actual wiring, mine is a dogs breakfast because I screwed up my wiring and couldn't be bothered reworking it 🫠