Problema con Laser Harp
salve tutti,
ho un problema con la mia laser harp precisamente nel codice riesco collegare serialmente l'arpa e successivamente con un programma di conversione seriale midi riesco collegarlo al programma midimoog v che ogni volta che tappo la fotoresistenza dal laser emette un impulso,che il programma rileva come midi,ma funziona solo per variare controlli come mixeraggio e altro,invece di suonare la nota.
questo e il code che ho usato
vi ringrazio anticipatamente
dy94
ho un problema con la mia laser harp precisamente nel codice riesco collegare serialmente l'arpa e successivamente con un programma di conversione seriale midi riesco collegarlo al programma midimoog v che ogni volta che tappo la fotoresistenza dal laser emette un impulso,che il programma rileva come midi,ma funziona solo per variare controlli come mixeraggio e altro,invece di suonare la nota.
code: [select]
midi-enabled laser harp
see: midi technical specifications
http://en.wikipedia.org/wiki/midi#technical_specifications
*/
#define midi_laser_count 9
#define midi_laser_octave_down 0
#define midi_laser_octave_up 8
short midicalibrateambientlight = 1023;
boolean midilaserstate[midi_laser_count] = {true, true, true, true, true, true, true, true, true};
byte midinotes[midi_laser_count] = {0, 0, 2, 4, 5, 7, 9, 11, 0};
byte midioctave = 5;
byte midipinlaser[midi_laser_count] = {3, 4, 5, 6, 7, 8, 9, 10, 11};
byte midipinvelocity = a0;
unsigned long midiratelimit[midi_laser_count] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
unsigned long midiratelimitthreshold = 35;
unsigned long midiratelimitthresholdoctave = 75;
byte midivelocity = 100;
void setup() {
calibrateambientlight();
midiinitserial();
midiinitpins();
midiintrosong();
}
void loop() {
midireadlasers();
midireadvelocity();
}
void calibrateambientlight() {
delay(100);
midicalibrateambientlight = analogread(midipinvelocity);
}
void midiintrosong() {
delay(1);
midisendnoteon(0, 55);
delay(125);
midisendnoteoff(64);
midisendnoteon(0, 55);
delay(125);
midisendnoteoff(64);
midisendnoteon(0, 55);
delay(125);
midisendnoteoff(67);
midisendnoteon(0, 55);
delay(250);
midisendnoteoff(72);
midisendnoteon(0, 55);
delay(125);
midisendnoteoff(67);
midisendnoteon(0, 55);
delay(500);
midisendnoteoff(72);
}
boolean midihandleoctave(byte thepin, boolean thestate) {
if (!thestate) {return true;}
if ((thepin == midi_laser_octave_down) && midioctave == 0) {return true;}
if ((thepin == midi_laser_octave_up) && midioctave == 9) {return true;}
midioctavekill();
switch(thepin) {
case midi_laser_octave_down:
midioctave--;
break;
case midi_laser_octave_up:
midioctave++;
break;
}
return false;
}
boolean midihandleratelimit(byte thepin) {
unsigned long themillis = millis();
unsigned long thethreshold = 0;
switch (thepin) {
case midi_laser_octave_down:
case midi_laser_octave_up:
thethreshold = midiratelimitthresholdoctave;
break;
default:
thethreshold = midiratelimitthreshold;
break;
}
if (themillis - midiratelimit[thepin] >= thethreshold) {
midiratelimit[thepin] = themillis;
return false;
}
return true;
}
void midihandlereadlaser(byte thepin, boolean thestate) {
if ((midilaserstate[thepin] != thestate) && midihandleratelimit(thepin)) {
midilaserstate[thepin] = thestate;
if ((thepin == midi_laser_octave_down) || (thepin == midi_laser_octave_up)) {
midihandleoctave(thepin, thestate);
} else if (thestate) {
midisendnoteon(midinotes[thepin] + (12 *midioctave), midivelocity);
} else {
midisendnoteoff(midinotes[thepin] + (12 *midioctave));
}
}
}
void midiinitpins() {
(byte thepin = 0; thepin < midi_laser_count; thepin++) {
pinmode(midipinlaser[thepin], input);
}
}
void midiinitserial() {
serial.begin(31250);
}
void midioctavekill() {
(byte thepin = 0; thepin < midi_laser_count; thepin++) {
if ((thepin == midi_laser_octave_down) || (thepin == midi_laser_octave_up)) {continue;}
midihandlereadlaser(thepin, high);
}
}
void midireadlasers() {
(byte thepin = 0; thepin < midi_laser_count; thepin++) {
midihandlereadlaser(thepin, digitalread(midipinlaser[thepin]));
}
}
void midireadvelocity() {
midivelocity = map(analogread(midipinvelocity), 0, midicalibrateambientlight, 1, 127);
}
void midisendcc(byte thecc, byte thevalue) {
serial.write(b10110000);
serial.write(thecc);
serial.write(thevalue);
}
void midisendnoteoff(byte thenote) {
serial.write(b10000000);
serial.write(thenote);
serial.write(0);
delay(1);
}
void midisendnoteon(byte thenote, byte thevelocity) {
serial.write(b10010000);
serial.write(thenote);
serial.write(thevelocity);
delay(1);
}
questo e il code che ho usato
![smiley :)](https://forum.arduino.cc/smileys/arduino/smiley.gif)
dy94
non si capisce una mazza della richiesta ![smiley-mr-green :smiley-mr-green:](https://forum.arduino.cc/smileys/arduino/smiley-mr-green.png)
![smiley-mr-green :smiley-mr-green:](https://forum.arduino.cc/smileys/arduino/smiley-mr-green.png)
Arduino Forum > International > Italiano > Software (Moderator: leo72) > Problema con Laser Harp
arduino
Comments
Post a Comment