Hello, trying to provide Pitch values to
an MPC-4822 DAC via Arduino Midi-Note in's
The Pitch is sended, i hear from the Monotron,
but it gets short notes, help me out please.
Here is the Scetch
#define DATAOUT 11//MOSI - serial data input
#define DATAIN 12//MISO - not used, but part of builtin SPI
#define SPICLOCK 13//sck - serial clock input
#define SLAVESELECT0 10//ss for 1st DAC - chip select input for 1st DAC
//#define SLAVESELECT1 9//ss for 2nd DAC - chip select input for 2nd DAC
#include "Spi.h"
byte incomingByte;
byte note;
byte velocity;
const int kGatePin = 9;
int action=2;
void setup() {
Serial.begin(31250);
pinMode(kGatePin, OUTPUT);
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
digitalWrite(3, LOW); // GND 0 Volt supply to opto-coupler
digitalWrite(2, HIGH);
Serial.begin(31250);
}
void sendNote(int key) {
int pitch = 0xa00L * key / 12;
digitalWrite(SS_PIN, LOW);
Spi.transfer(0x10 + (pitch >> 8));
Spi.transfer(pitch & 0xff);
digitalWrite(SS_PIN, HIGH);
}
void loop() {
if (Serial.available() > 0) {
// read the incoming byte:
incomingByte = Serial.read();
// wait for as status-byte, channel 1, note on or off
if (incomingByte== 144){ // note on message starting starting
action=1;
}else if (incomingByte== 128){ // note off message starting
action=0;
}else if (incomingByte== 208){ // aftertouch message starting
//not implemented yet
}else if (incomingByte== 160){ // polypressure message starting
//not implemented yet
}else if ( (action==0)&&(note==0) ){ // if we received a "note off", we wait for which note (databyte)
note=incomingByte;
playNote(note, 0);
note=0;
velocity=0;
action=2;
}else if ( (action==1)&&(note==0) ){ // if we received a "note on", we wait for the note (databyte)
note=incomingByte;
}else if ( (action==1)&&(note!=0) ){ // ...and then the velocity
velocity=incomingByte;
playNote(note, velocity);
note=0;
velocity=0;
action=0;
}else{
//nada
}
}
}
void playNote(byte note, byte velocity){
if (velocity >10){
digitalWrite(kGatePin, HIGH);
}else{
digitalWrite(kGatePin, LOW);
}
//since we don't want to "play" all notes we wait for a note between 36 & 44
if(note>=36 && note<53){
byte key=note-36; // to get a pinnumber between 2 and 9
sendNote(key);
}
}