Hi Guys,
so I am currently creating this project and got a little stuck with something I guess is super easy for a lot of you guys.
I'm a super newbie to all kind of programming, and although I was super enthusiastic about getting it done myself (which means copying together the working bits), my head just seems to pause instantly, when I try to read about Interrupts...
I am building a Midi-triggered device, that uses solenoids to play inside a Fender Rhodes. The tines basically just create a sound if they are hit really really shortly.
Ok, so I am having a couple of PWM Outputs, which are triggered by a Midi Note and all I want is to use Note On to put out the Velocity and then after a short break cut the output back to 0. Obviously that is easly accomplished by using delay(), but this tends to overflow the processor if I understand correctly???!!
So far I managed to get the wanted results by just chopping the Midi Notes in my DAW as short as I wanted and using the Note Off to cut everything down.
I am really sorry for this mess of a code, but then again I am already quite glad I even got this far
Hope someone can help me.
Thank you!!!
so I am currently creating this project and got a little stuck with something I guess is super easy for a lot of you guys.
I'm a super newbie to all kind of programming, and although I was super enthusiastic about getting it done myself (which means copying together the working bits), my head just seems to pause instantly, when I try to read about Interrupts...
I am building a Midi-triggered device, that uses solenoids to play inside a Fender Rhodes. The tines basically just create a sound if they are hit really really shortly.
Ok, so I am having a couple of PWM Outputs, which are triggered by a Midi Note and all I want is to use Note On to put out the Velocity and then after a short break cut the output back to 0. Obviously that is easly accomplished by using delay(), but this tends to overflow the processor if I understand correctly???!!
So far I managed to get the wanted results by just chopping the Midi Notes in my DAW as short as I wanted and using the Note Off to cut everything down.
I am really sorry for this mess of a code, but then again I am already quite glad I even got this far
Hope someone can help me.
Code:
// USB MIDI receive example, Note on/off -> LED on/off
// contributed by Alessandro Fasan
const int PMW1 = 3;
const int PMW2 = 4;
const int PMW3 = 5;
const int PMW4 = 6;
const int PMW5 = 9;
const int PMW6 = 10;
const int PMW7 = 23;
const int PMW8 = 22;
const int LED = 13;
int Velo;
//unsigned long currentMillis;
const long DEL = 100;
const int LowV = 240;
unsigned long t = 0;
void setup()
{
Serial.begin(115200);
pinMode(LED, OUTPUT);
pinMode(PMW1, OUTPUT);
pinMode(PMW2, OUTPUT);
pinMode(PMW3, OUTPUT);
pinMode(PMW4, OUTPUT);
pinMode(PMW5, OUTPUT);
pinMode(PMW6, OUTPUT);
pinMode(PMW7, OUTPUT);
pinMode(PMW8, OUTPUT);
usbMIDI.setHandleNoteOn(OnNoteOn) ;
usbMIDI.setHandleNoteOff(OnNoteOff);
}
void loop() //im loop wird druchgehen der Midi Eingang ausgelesen
{
usbMIDI.read();
}
void OnNoteOn ( byte channel , byte note , byte velocity) //hier werden die NoteOn Befehle ausgelesen
{
if ( note == 60) //note 60 entspricht einem C3 und ist nur der Einfachheit halber ausgewählt. Ab dem C3 gehts chromatisch hoch
{
Velo = map(velocity, 0, 127, LowV, 255); //um die Velocity auf den Hubmagneten zu übertragen muss sie auf die PMW umgerechnet werden.
analogWrite(PMW1, Velo);
}
if ( note == 61)
{
Velo = map(velocity, 0, 127, LowV, 255);
analogWrite(PMW2, Velo);
//delay(DEL); //diese Delay-Schleife muss anders gelöst werden - Timer Interrupt
//analogWrite(PMW2, 0);
}
if ( note == 62)
{
Velo = map(velocity, 0, 127, LowV, 255);
analogWrite(PMW3, Velo);
}
if ( note == 63)
{
Velo = map(velocity, 0, 127, LowV, 255);
analogWrite(PMW4, Velo);
//delay(DEL);
//analogWrite(PMW4, 0);
}
if ( note == 64)
{
Velo = map(velocity, 0, 127, LowV, 255);
analogWrite(PMW5, Velo);
}
if ( note == 65)
{
Velo = map(velocity, 0, 127, LowV, 255);
analogWrite(PMW6, Velo);
}
if ( note == 66)
{
Velo = map(velocity, 0, 127, LowV, 255);
analogWrite(PMW7, Velo);
}
if ( note == 67)
{
Velo = map(velocity, 0, 127, LowV, 255);
analogWrite(PMW8, Velo);
}
}
void OnNoteOff ( byte channel , byte note, byte velocity) //durch den NoteOFF befehlt wird der Ausgang direkt auf LOW gesetzt.
{
if ( note == 60)
{
analogWrite(PMW1, 0);
}
if ( note == 61)
{
analogWrite(PMW2, 0);
}
if ( note == 62)
{
analogWrite(PMW3, 0);
}
if ( note == 63)
{
analogWrite(PMW4, 0);
}
if ( note == 64)
{
analogWrite(PMW5, 0);
}
if ( note == 65)
{
analogWrite(PMW6, 0);
}
if ( note == 66)
{
analogWrite(PMW7, 0);
}
if ( note == 67)
{
analogWrite(PMW8, 0);
}
}
Thank you!!!