# Drawing movement of 2 accelerometers

**URL:** https://discourse.processing.org/t/drawing-movement-of-2-accelerometers/22446
**Category:** Electronics (Arduino, etc.)
**Created:** [July 7, 2020, 11:49am UTC](https://discourse.processing.org/t/drawing-movement-of-2-accelerometers/22446 "2020-07-07T11:49:51Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Matthias\_db](https://avatars.discourse-cdn.com/v4/letter/m/a5b964/32.png) [@Matthias\_db](https://discourse.processing.org/u/Matthias_db)
#### Post date: [July 7, 2020, 11:49am UTC](https://discourse.processing.org/t/drawing-movement-of-2-accelerometers/22446/1 "2020-07-07T11:49:51Z")

</div>

hello, i want to simulate the movement of 2 accelerometers in one drawing. the 2 boxes that i draw should move differently from each other. i managed to get my first box moving but i can not include another moving box.

the code i used for the first box is:

\<  
void draw() {  
translate(width/2, height/2, 0);  
background(100);  
textSize(22);  
fill(#FFFFFF);  
text("Roll: " + int(roll1) + " Pitch: " + int(pitch1), -100, 265);  
// Rotate the object  
rotateX(radians(roll1));  
rotateZ(radians(-pitch1));

> 

the roll1 and pitch1 are coming from my serial port which i read.

So my question is can i include my seccond movement in this drawing and if so, how can i do this

underneath u will find full code:  
\<  
import processing.serial.\*;  
import java.awt.event.KeyEvent;  
import java.io.IOException;

Serial myPort;  
String data=“”;  
float roll1, pitch1;  
float roll2, pitch2;  
void setup() {  
size (960, 640, P3D);  
myPort = new Serial(this, “COM7”, 9600); // starts the serial communication  
myPort.bufferUntil(‘\n’);  
}  
void draw() {  
translate(width/2, height/2, 0);  
background(100);  
textSize(22);  
fill(#FFFFFF);  
text("Roll: " + int(roll1) + " Pitch: " + int(pitch1), -100, 265);  
// Rotate the object  
rotateX(radians(roll1));  
rotateZ(radians(-pitch1));

// 3D 0bject  
fill(#F70707);  
box(4,1,2);

}  
// Read data from the Serial Port  
void serialEvent (Serial myPort) {  
// reads the data from the Serial Port up to the character ‘.’ and puts it into the String variable “data”.  
data = myPort.readStringUntil(‘\n’);  
// if you got any bytes other than the linefeed:  
if (data != null) {  
data = trim(data);  
// split the string at “/”  
String items = split(data, ‘/’);  
if (items.length \> 1) {  
//— Roll,Pitch in degrees  
roll1 = float(items[0]);  
pitch1 = float(items[1]);  
roll2 = float(items[2]);  
pitch2 = float(items[3]);  
}  
}  
}

> 

the com port gives me this information:  
62.46/-7.55/62.46/-7.55  
62.45/-7.54/62.45/-7.54  
62.46/-7.54/62.46/-7.54  
62.47/-7.55/62.47/-7.55  
62.46/-7.54/62.46/-7.54  
62.44/-7.55/62.44/-7.55  
62.44/-7.54/62.44/-7.54  
62.43/-7.56/62.43/-7.56  
62.45/-7.57/62.45/-7.57  
62.45/-7.58/62.45/-7.58  
62.45/-7.56/62.45/-7.56  
62.44/-7.57/62.44/-7.57  
62.44/-7.56/62.44/-7.56  
62.46/-7.55/62.46/-7.55

---

<div class="post-metadata">

### Author: ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)
#### Post date: [July 7, 2020, 1:26pm UTC](https://discourse.processing.org/t/drawing-movement-of-2-accelerometers/22446/2 "2020-07-07T13:26:06Z")

</div>

Hello,

Please format your code as a courtesy to the community, for readability and to make it easy to copy code:  
[https://discourse.processing.org/faq#format-your-code](https://discourse.processing.org/faq#format-your-code)

Try to cut and paste your code into Processing and you will understand.

When you hover over the code example below I can use the copy icon that pops up in upper right.

Example:

```auto
void setup() 
	{
  size(700, 150);
  background(0);
  fill(0, 255, 0);
  textAlign(CENTER, CENTER);
  textSize(48);
  text("Please format your code. :)", width/2, height/2-10);
	}

```

`:)`
