Problem with pitches and serial read
in
Contributed Library Questions
•
7 months ago
Hi everyone, again, I have this code, but when I run it works ok, but if you see the println there are a mistake, the code don´t read the number 14 that correspond the pitch 83, starts in the number 13 that correspond at pitch 81, I need it for the conexion with arduino.
import arb.soundcipher.*;
import arb.soundcipher.constants.*;
import processing.serial.*; //llama a todas las intruccionnes con todas las extenciones
Serial mipuerto; // declaramos el puerto serial para abilitar el puerto donde se le enviara informacion a arduino esto es una variable de tipo serial
SoundCipher part1 = new SoundCipher(this);
float[] pitches = {83, 81, 80, 78,76, 74, 73, 71, 69, 67, 66, 64, 62, 60, 59, 57 };
float[] dynamics = new float[pitches.length];
float[] durations = {1,1,1,2,1,1,1,2,1,1,1,2,1,1,1,4,1};
float y;
int n = 0;
float xLoc = 0.0;
boolean test = false;
//Del siguiente arreglo las unidades indican dedo, decenas indican cuerda
int[] pitch_to_LED = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // octava 0, pitch 0 a 11
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // octava 1, pitch 12 a 23
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // octava 2, pitch 24 a 35
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // octava 3, pitch 36 a 47
0, 0, 0, 0, 0, 0, 0, 0, 0, 41, 0, 42, // octava 4, pitch 48 a 59
43, 0, 44, 0, 31, 0, 32, 33, 0, 34, 0, 21, // octava 5, pitch 60 a 71
0, 22, 23, 0, 24, 0, 11, 0, 12, 13, 0, 14, // octava 6, pitch 72 a 83
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // octava 7, pitch 84 a 95
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // octava 8, pitch 96 a 107
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // octava 9, pitch 108 a 119
0, 0, 0, 0, 0, 0, 0 //, 0, 0, 0, 0, 0, // octava 10, pitch 120 a 127
};
void setup(){
println(Serial.list());
String Puerto = Serial.list()[1];
mipuerto = new Serial(this,Puerto,9600);
for (int i=0; i<pitches.length; i++) {
dynamics[i] = random(40) + 70;
}
background(0);
size(640, 360);
stroke(255);
frameRate(2);
}
void draw()
{
if (n >= pitches.length-1) {
n = 0;
}
if (xLoc > width) {
background(0);
xLoc = 0.0;
}
line(0, 169.5, 640, 169.5);
line(0, 158.5, 640, 158.5);
line(0, 147.5, 640, 147.5);
line(0, 137, 640, 137);
line(0, 125.5, 640, 125.5);
line(xLoc-2.5, height-3*pitches[n], xLoc-2.5, pitches[n]*2 );
ellipse(xLoc, height-3*pitches[n], 5 , 5);
part1.playNote(pitches[n], dynamics[n], durations[n]);
n += 1;
xLoc += 20.0;
int newNotas = int(pitches[n]);
//mipuerto.write(newNotas);
mipuerto.write(pitch_to_LED[newNotas]);
println(pitch_to_LED[newNotas]);
}
1