Δευτέρα 18 Ιανουαρίου 2010

ΠΡΟΒΛΗΜΑ ΜΕ ΕΙΣΑΓΩΓΗ ΣΤΟΙΧΕΙΩΝ ΣΕ ΠΙΝΑΚΑ ΣΤΟ processing

Για να χρησιμοποιησω τα στοιχεια που παιρνω απο το Arduino, πρεπει να τα εισαγω σε εναν πινακα. Εκει βρισκεται το προβλημα. Σε ενα αλλο αρχειο με 3 εισαγωμενα στοιχεια, τα πραγματα δουλευουν σωστα, στο συγκεκριμενο ομως οχι. Με τους ηχους δεν παρουσιαζεται προβλημα.

// processing code
import processing.serial.*;
// Import the Sonia library
import pitaru.sonia_v2_9.*;
// Sample objects for the sounds
Sample box_blue_1;
Sample box_blue_2;
Sample box_blue_3;
Sample box_blue_4;

Sample box_orange_1;
Sample box_orange_2;
Sample box_orange_3;
Sample box_orange_4;

Sample box_green_1;
Sample box_green_2;
Sample box_green_3;
Sample box_green_4;

Sample box_yellow_1;
Sample box_yellow_2;
Sample box_yellow_3;
Sample box_yellow_4;

Sample box_over_analog_1;
Sample box_over_analog_2;
Sample box_over_analog_3;
Sample box_over_analog_4;
Sample box_over_analog_5;
Sample box_over_analog_6;

//vars for arduino's array and sound volume
float blueBox1 = 0;
float bb1=0;
float blueBox2 = 0;
float bb2 =0;
float blueBox3 = 0;
float bb3=0;
float blueBox4 = 0;
float bb4=0;

float orangeBox1 = 0;
float ob1=0;
float orangeBox2 = 0;
float ob2=0;
float orangeBox3 = 0;
float ob3=0;
float orangeBox4 = 0;
float ob4=0;

float greenBox1 = 0;
float gb1=0;
float greenBox2 = 0;
float gb2=0;
float greenBox3 = 0;
float gb3=0;
float greenBox4 = 0;
float gb4=0;

float yellowBox1 = 0;
float yb1=0;
float yellowBox2 = 0;
float yb2=0;
float yellowBox3 = 0;
float yb3=0;
float yellowBox4 = 0;
float yb4=0;

float ab1=0;
float ab2=0;
float ab3=0;
float ab4=0;
float ab5=0;
float ab6=0;


Serial myPort;

void setup() {

Sonia.start(this);
// load sound files
box_blue_1 = new Sample( "boo boo boo.wav" );
box_blue_2 = new Sample( "dj.wav" );
box_blue_3 = new Sample( "gruniara01.wav" );
box_blue_4 = new Sample( "gruniara02.wav" );

box_orange_1 = new Sample( "gruniara03.wav" );
box_orange_2 = new Sample( "gruniara04.wav" );
box_orange_3 = new Sample( "gruniara05.wav" );
box_orange_4 = new Sample( "hight02.wav" );

box_green_1 = new Sample( "low01.wav" );
box_green_2 = new Sample( "phaser01.wav" );
box_green_3 = new Sample( "phaser02.wav" );
box_green_4 = new Sample( "phaser03.wav" );

box_yellow_1 = new Sample( "phaser04.wav" );
box_yellow_2 = new Sample( "trainboom a.wav" );
box_yellow_3 = new Sample( "trainboom b.wav" );
box_yellow_4 = new Sample( "wahwah01.wav" );

box_over_analog_1 = new Sample ("wahwah02.wav");
box_over_analog_2 = new Sample ("wahwah03.wav");
box_over_analog_3 = new Sample ("wahwah04.wav");
box_over_analog_4 = new Sample ("wiuwiu.wav");
box_over_analog_5 = new Sample ("wiuwiu2.wav");
box_over_analog_6 = new Sample ("zbubble01.wav");


// play sound files
box_blue_1.play();
box_blue_2.play();
box_blue_3.play();
box_blue_4.play();

box_orange_1.play();
box_orange_2.play();
box_orange_3.play();
box_orange_4.play();

box_green_1.play();
box_green_2.play();
box_green_3.play();
box_green_4.play();

box_yellow_1.play();
box_yellow_2.play();
box_yellow_3.play();
box_yellow_4.play();

box_over_analog_1.play();
box_over_analog_2.play();
box_over_analog_3.play();
box_over_analog_4.play();
box_over_analog_5.play();
box_over_analog_6.play();

box_blue_1.setVolume(bb1);
box_blue_2.setVolume(bb2);
box_blue_3.setVolume(bb3);
box_blue_4.setVolume(bb4);

box_orange_1.setVolume(ob1);
box_orange_2.setVolume(ob2);
box_orange_3.setVolume(ob3);
box_orange_4.setVolume(ob4);

box_green_1.setVolume(gb1);
box_green_2.setVolume(gb2);
box_green_3.setVolume(gb3);
box_green_4.setVolume(gb4);

box_yellow_1.setVolume(yb1);
box_yellow_2.setVolume(yb2);
box_yellow_3.setVolume(yb3);
box_yellow_4.setVolume(yb4);

box_over_analog_1.setVolume(ab1);
box_over_analog_2.setVolume(ab2);
box_over_analog_3.setVolume(ab3);
box_over_analog_4.setVolume(ab4);
box_over_analog_5.setVolume(ab5);
box_over_analog_6.setVolume(ab6);



// List all the available serial ports
println(Serial.list());
// my usb port is 1
myPort = new Serial(this, Serial.list()[1], 57600);
// don't generate a serialEvent() unless you get a newline character:
myPort.bufferUntil('\n');

box_blue_1.repeat();
box_blue_2.repeat();
box_blue_3.repeat();
box_blue_4.repeat();

box_orange_1.repeat();
box_orange_2.repeat();
box_orange_3.repeat();
box_orange_4.repeat();

box_green_1.repeat();
box_green_2.repeat();
box_green_3.repeat();
box_green_4.repeat();

box_yellow_1.repeat();
box_yellow_2.repeat();
box_yellow_3.repeat();
box_yellow_4.repeat();

box_over_analog_1.repeat();
box_over_analog_2.repeat();
box_over_analog_3.repeat();
box_over_analog_4.repeat();
box_over_analog_5.repeat();
box_over_analog_6.repeat();
}

void draw() {
//not necessary
box_blue_1.setVolume(bb1);
box_blue_2.setVolume(bb2);
box_blue_3.setVolume(bb3);
box_blue_4.setVolume(bb4);

box_orange_1.setVolume(ob1);
box_orange_2.setVolume(ob2);
box_orange_3.setVolume(ob3);
box_orange_4.setVolume(ob4);

box_green_1.setVolume(gb1);
box_green_2.setVolume(gb2);
box_green_3.setVolume(gb3);
box_green_4.setVolume(gb4);

box_yellow_1.setVolume(yb1);
box_yellow_2.setVolume(yb2);
box_yellow_3.setVolume(yb3);
box_yellow_4.setVolume(yb4);

box_over_analog_1.setVolume(ab1);
box_over_analog_2.setVolume(ab2);
box_over_analog_3.setVolume(ab3);
box_over_analog_4.setVolume(ab4);
box_over_analog_5.setVolume(ab5);
box_over_analog_6.setVolume(ab6);

}

void serialEvent(Serial myPort) {
// get the ASCII string:
String inString = myPort.readStringUntil('\n');

if (inString != null) {
// trim off any whitespace:
inString = trim(inString);
// split the string on the commas and convert the
// resulting substrings into an integer array:
float[] boxes = float(split(inString, ",")); // EDW EINAI TO PROVLIMA
// check the results
println(boxes[1]); // DEN VAZEI TA DEDOMENA SE OLES TIS THESEIS TOU PINAKA PARA MONO STO boxes[1] KAI OTAN TIPONO KAPOIO ALLO KARASAREI
// if the array has at least 16 elements, I got
// the whole thing. I put the numbers in the
// boxes variables:
if (boxes.length >=16) {// DEN EKTELEITAI KAN

blueBox1 = boxes[0];
blueBox2 = boxes[1];
blueBox3 = boxes[2];
blueBox4 = boxes[3];

orangeBox1 = boxes[4];
orangeBox2 = boxes[5];
orangeBox3 = boxes[6];
orangeBox4 = boxes[7];

greenBox1 = boxes[8];
greenBox2 = boxes[9];
greenBox3 = boxes[10];
greenBox4 = boxes[11];

yellowBox1 = boxes[12];
yellowBox2 = boxes[13];
yellowBox3 = boxes[14];
yellowBox4 = boxes[15];

// i change the sound volumes
// DIGITAL INPUTS
if (blueBox1==1) {
bb1=1;
}
else {
bb1=0;
}


if (blueBox2==1) {
bb2=1;
}
else {
bb2=0;
}


if (blueBox3==1) {
bb3=1;
}
else {
bb3=0;
}


if (blueBox4==1) {
bb4=1;
}
else {
bb4=0;
}


if (orangeBox1==1) {
ob1=1;
}
else {
ob1=0;
}


if (orangeBox2==1) {
ob2=1;
}
else {
ob2=0;
}


if (orangeBox3==1) {
ob3=1;
}
else {
ob3=0;
}


if (orangeBox4==1) {
ob4=1;
}
else {
ob4=0;
}


if (greenBox1==1) {
gb1=1;
}
else {
gb1=0;
}


if (greenBox2==1) {
gb2=1;
}
else {
gb2=0;
}

//ANALOG INPUTS
if (greenBox3>=1020) {
gb3=1;
}
else {
gb3=0;
}


if (greenBox4>=1020) {
gb4=1;
}
else {
gb4=0;
}


if (yellowBox1>=1020) {
yb1=1;
}
else {
yb1=0;
}


if (yellowBox2>=1020) {
yb2=1;
}
else {
yb2=0;
}


if (yellowBox3>=1020) {
yb3=1;
}
else {
yb3=0;
}


if (yellowBox4>=1020) {
yb4=1;
}
else {
yb4=0;
}
}
}
}
void stop()
{
// i must stop the Sonia Library
Sonia.stop();
super.stop();
}

για τα αρχεια των ηχων επικοινωνειστε με mail.

Δεν υπάρχουν σχόλια:

Δημοσίευση σχολίου