Skip to content

Instantly share code, notes, and snippets.

@wyan
Created March 5, 2019 14:41
Show Gist options
  • Save wyan/50c294612bf75c776fe2fd46dd448cef to your computer and use it in GitHub Desktop.
Save wyan/50c294612bf75c776fe2fd46dd448cef to your computer and use it in GitHub Desktop.
ATTiny85 based MIDI to CV
Requires https://github.com/heartscrytech/DigisparkMIDI
Bootloader https://github.com/micronucleus/micronucleus
See instructions at https://janostman.wordpress.com/cheap-diy-usb-midi-to-cv-interface/
void usbFunctionWriteOut(uchar * data, uchar len) {
uint8_t note=data[2]; //Get note for key on/off
if (note<36) note=36; //If note is lower than C2 set it to C2
note=note-36; //Subtract 36 to get into CV range
if (note>60) note=60; //If note is higher than C7 set it to C7
if (data[1] == 0x90) { //If note on
digitalWrite(5, HIGH); //Set Gate HIGH
OCR1A = note<<2; //Multiply note by 4 to set the voltage (1v/octave)
}
if (data[1] == 0x80) { //If note off
digitalWrite(5, LOW); //Set Gate LOW
OCR1A = note<<2; //Multiply note by 4 to set the voltage (1v/octave)
}
}
#include <DigiMIDI.h>
DigiMIDIDevice midi;
void setup() {
pinMode(1,OUTPUT); //Pitch is output
pinMode(5, OUTPUT); //Gate is output
//Setup Timer1 to do PWM DAC for Pitch
TCCR1 = _BV(PWM1A) | _BV(COM1A1) | _BV(CS10);
GTCCR = 0;
OCR1C = 239;
OCR1A = 0; //Set initial Pitch to C2
digitalWrite(5,LOW); //Set initial Gate to LOW;
}
void loop() {
midi.update(); //Check if any MIDI data is received
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment