Hello guys,
I'm having trouble trying to run a program, I hope this is not too confusing. I will break down this problem into two parts.
I'm basically trying to interface an accelerometer with arduino UNO, my task is to draw a sphere which will simulate the movement of the accelerometer as I tilt it in different directions based on the X, Y and Z coordinates. When I run the program individually, that is, when I run the program that simulates the sphere rotating and in another file I run a program that just prints the X,Y and Z values of the accelerometer they both run perfectly, the problem comes when I put both codes together and then I run it, I get an error that says "Error inside Serial.()".
I changed the position of the line of code "arduino = new Arduino(this, Arduino.list()[1], 57600);" within the "void setup" method and then the program runs but the sphere won't move. Can anybody help me run this program?
import processing.serial.;
import cc.arduino.;
import processing.opengl.*;
Arduino arduino;
int array[] = {0,1,2};
void setup() {
frameRate(30);
arduino = new Arduino(this, Arduino.list()[1], 57600);
size(450, 450, OPENGL);
fill(238,203,173, 100);
stroke(248,248,255);
// fill(0,0,205, 100); it is just a blue sphere
}
void draw() {
int xVal = arduino.analogRead(array[0]);
int yVal = arduino.analogRead(array[1]);
int zVal = arduino.analogRead(array[2]);
background(0);
translate(width/2, height/2);
sphere(100);
//sphereDetail(20,20);
rotateX(xVal);
rotateY(yVal);
rotateZ(zVal);
println(" X"+"\t"+" Y"+"\t"+" Z");
println(xVal+"\t"+yVal+"\t"+zVal); //Values given by accelerometer
delay(100);
}
This might also be a bit confusing, it also has to do with a bit of Math:
I converted the X and Y readings from the accelerometer by mapping the values into degrees (eg. for X: 355-522 -----> 0 - 90º). I only knew how to do it with the readings from the X and Y axis, however, having the X and Y values in degrees, is there any way I can calculate Z? is there any way I can calculate that Z position in space, given in this case in degrees? maybe it is easier to understand this if we imagine a dot or just "any object" you want to think of somewhere in a spherical coordinate system.
Thanks a million!!!