Skip to content

Instantly share code, notes, and snippets.

@johndoe46
Created May 2, 2016 19:06
Show Gist options
  • Save johndoe46/5b46f3b4b09e02b5f27f0443b198e27c to your computer and use it in GitHub Desktop.
Save johndoe46/5b46f3b4b09e02b5f27f0443b198e27c to your computer and use it in GitHub Desktop.
/*
Adapted from denkitribe's code, which can be found here:
http://code.google.com/p/denkitribe/source/browse/trunk/Arduino/MonotronCVGateTest/MonotronCVGateTest.pde
pin setup: - DAC 1 ---> Arduino +5V
- DAC 2 ---> Arduino 10
- DAC 3 ---> Arduino 13
- DAC 4 ---> Arduino 11
- DAC 5 ---> Gnd
- DAC 6 ---> Not Connected
- DAC 7 ---> Arduino Gnd
- DAC 8 ---> CV Out
For information on why the pins are configured this way see the links below:
MCP4822 datasheet - http://ww1.microchip.com/downloads/en/devicedoc/21953a.pdf
SPI library - http://www.arduino.cc/playground/Code/Spi
*/
#include <SPI.h>
const int SS_PIN = 10; //SPI select slave pin
const int gatePin = 2;
void setup () {
pinMode(SS_PIN, OUTPUT);
SPI.begin();
}
void sendNote (int key) {
int pitch = 0xa00l * key / 12; //divide by 12 to map to one octave
digitalWrite(SS_PIN, LOW); //DAC is selected when LOW
SPI.transfer(0x10 + (pitch >> 8));
SPI.transfer(pitch & 0xff);
digitalWrite(SS_PIN, HIGH); //Deselect DAC
digitalWrite(gatePin, HIGH); //send gate signal
delay(90);
digitalWrite(gatePin, LOW); //stop sending gate signal
delay(10);
}
void loop () {
sendNote(0);
sendNote(12);
sendNote(11);
sendNote(12);
sendNote(16);
sendNote(12);
sendNote(11);
sendNote(12);
sendNote(0);
sendNote(12);
sendNote(10);
sendNote(12);
sendNote(16);
sendNote(12);
sendNote(10);
sendNote(12);
sendNote(0);
sendNote(12);
sendNote(9);
sendNote(12);
sendNote(16);
sendNote(12);
sendNote(9);
sendNote(12);
sendNote(0);
sendNote(12);
sendNote(8);
sendNote(12);
sendNote(16);
sendNote(12);
sendNote(8);
sendNote(12);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment