// MONOPHONIC CV to MIDI adaptor for Monophonic synthisizers.
void xprintf(const char *format, ...); // programmer misses printf, so sue me.
int gateLevel = 0;
int gateOld = 0;
int noteNum = 0;
int noteOld = 0;
int midCh = 1;
class fakeMIDI {
public:
void begin(unsigned char);
void sendNoteOn(unsigned char, unsigned char, unsigned char);
void sendNoteOff(unsigned char, unsigned char, unsigned char);
private:
};
void fakeMIDI::begin(unsigned char x)
{
xprintf("begin MIDI object %d\n", x);
}
void fakeMIDI::sendNoteOn(unsigned char theNote, unsigned char theIDK, unsigned char theChannel)
{
xprintf("note %2d ON w/ IDK %3d.\n", theNote, theIDK);
}
void fakeMIDI::sendNoteOff(unsigned char theNote, unsigned char theIDK, unsigned char theChannel)
{
xprintf("note %2d OFF w/ IDK %3d.\n", theNote, theIDK);
}
fakeMIDI MIDI;
//
void setup()
{
mySetup(115200);
xprintf("\nhello world.\n");
MIDI.begin(222);
pinMode(A1, INPUT_PULLUP);
}
void loop() {
int pitchPin = analogRead(A0); // read analog pins
int gatePin = !digitalRead(A1);
float voltage = pitchPin * (5.0 / 1023.0); // get voltage for pitch cv input
int noteNum = (voltage / 0.08) + 24;
noteNum = map(pitchPin, 0, 1024, 48, 62); // remove. just making the steps big
gateLevel = gatePin; // digital input now
// checks for various changed conditions and send midi command as appropriate.
if (gateLevel == 1) {
if (gateLevel != gateOld) {
MIDI.sendNoteOn((noteNum), 127, (midCh));
}
if (noteNum != noteOld) {
MIDI.sendNoteOff((noteOld), 0, (midCh));
delay(29);
MIDI.sendNoteOn((noteNum), 127, (midCh));
noteOld = noteNum; // currently playing note
}
}
if (gateLevel != gateOld) {
if (!gateLevel) {
MIDI.sendNoteOff((noteNum), 0, (midCh)); // send noteOff command for noteNum and NoteOld
if (noteNum != noteOld) {
MIDI.sendNoteOff((noteOld), 0, (midCh));
xprintf(" yes?\n");
noteOld = noteNum;
}
}
}
gateOld = gateLevel;
delay(50);
}
//
// programmer misses printf...
void xprintf(const char *format, ...)
{
char buffer[256];
va_list args;
va_start(args, format);
vsprintf(buffer, format, args);
va_end(args);
Serial.print(buffer);
}
// programmer forgets day of week, version
void mySetup(unsigned long bandRate)
{
Serial.begin(bandRate);
char s[] = __FILE__;
byte b = sizeof(s);
while ( (b > 0) && (s[b] != 47)) b--;
char *u = s + b + 1;
xprintf("\nHEllo WOrld!\n");
xprintf("%s %s\n\n", __DATE__, u);
xprintf("!\n");
}
GATE
PITCH
CLOSE