I haven't used an arduino in a long time so I'm not too familiar with the language anymore.
I've been playing around with Mozzi's library and some pots generating some sound, I want to be able to play a midi file from ableton, which changes the pitch of one of the variables in the Mozzi code. Such as replacing the pitch pot with midi from ableton. I've setup a virtual midi port on mac. And I ran some arduino midi example code to blink an LED on recieving midi input and that works. Although I don't know where to start when it comes to using that Midi info from Ableton to an arduino and change the pitch of a Mozzi Library sketch.
I have the following code, which should blink an LED when receiving any midi note. And some other code which should change the frequency of the Mozzi Library sketch. The LED blinks as it should however, as soon as the arduino receives any midi the sound cuts out and the LED keeps blinking.
Here is my code:
#include <MozziGuts.h>
#include <Oscil.h> // oscillator
#include <tables/sin2048_int8.h> // table for Oscils to play
#include <Smooth.h>
#define CONTROL_RATE 128
const int PIEZO_PIN = 3; // set the analog input pin for the piezo
const byte PWMDAC1pin = 9; // PWM DAC, only pins 9 and 10 are allowed
const byte PWMDAC2pin = 10; // example using second DAC
const byte period = 32; // for 8 bit DAC
byte commandByte;
byte noteByte;
byte velocityByte;
byte noteOn = 144;
// use: Oscil <table_size, update_rate> oscilName (wavetable), look in .h file of table #included above
Oscil <SIN2048_NUM_CELLS, AUDIO_RATE> aSin(SIN2048_DATA);
void setup(){
pinMode(13,OUTPUT);
digitalWrite(13,LOW);
//Serial.begin(9600); // for Teensy 3.1, beware printout can cause glitches
Serial.begin(115200); // set up the Serial output so we can look at the piezo values // set up the Serial output so we can look at the piezo values
startMozzi(CONTROL_RATE); // :)) use the control rate defined above
}
void updateControl(){
// read the piezo
do{
if (Serial.available()){
commandByte = Serial.read();//read first byte
noteByte = Serial.read();//read next byte
velocityByte = Serial.read();//read final byte
if (commandByte == noteOn){//if note on message
if ( velocityByte > 0){
int piezo_value = noteByte; // value is 0-1023
int frequency = piezo_value*3; // calibrate
aSin.setFreq(frequency);
digitalWrite(13,HIGH);//turn on led
pinMode(5,OUTPUT);
}
}
else if(commandByte == 128){
digitalWrite(13,LOW);
digitalWrite(9,LOW);
pinMode(5,OUTPUT);
}
}
// set the frequency
}
while (Serial.available() > 2);//when at least three bytes available
}
int updateAudio(){
return aSin.next();
}
void loop(){
updateControl();
audioHook();
delay(1);
//digitalWrite(13,LOW);//turn led off
}
@casperround64, please do not cross-post. Other thread removed. Threads merged.