Moving a cube in 3d, help needed.

here is the python code im using for blender 3d to move a 3d cube around one axis, I am using a potentiometer to control the position.. I want to know how can I use multiple potentiometer, like 2 more potentiometer and i can control position of box in 3d ? I am new to python, I don't know how to include multiple analog readings in python for more than one analog inputs from arduino ?

Thankyou

import serial
import Blender

serialport = serial.Serial('COM4', 9600)
ob = Blender.Object.Get ('Cube')
Blender.Window.WaitCursor(1)

for i in range(1, 500):
	x = serialport.read(size=1)
	y = 0.01*ord(x)
	#print "y=", y
	ob.setLocation(-3*y,2,2.55)
	ob.setEuler(0,0,y)
	ob.setSize(0.5,0.5,0.5)
	Blender.Redraw()
	if Blender.Window.TestBreak()==True:
		brake()	
		
else:
	serialport.close()
	Blender.Window.WaitCursor(0)

Arduino code:

void setup () {
  Serial.begin (9600);
}
void loop () {
  
Serial.print(analogRead(0)/4, BYTE);
delay (40);
}

How about this:

in python:

for i in range(1, 500):
	 x = serialport.read(size=1)
               y = serialport.read(size=1)
              z = serialport.read(size=1)

and in arduino:

void loop () {
  
Serial.print(analogRead(0)/4, BYTE);
Serial.print(analogRead(1)/4, BYTE);
Serial.print(analogRead(2)/4, BYTE);

delay (40);
}

However, there are some problems with this "protocol":

  1. You send positions all the time, even if the potentiometer doesn't move. You will see this in speed that you can move the cube at the slow baud rate.
  2. You have no way of syncronizing the communication. You will see this when you start the arduino, then start the blender script. Sometimes your #1 potentiometer will be X, sometimes Y, sometimes Z, because you aren't syncing the xyz.

You could modify your python and arduino code like this to account for #2: (I don't know python - but in C this is what I would do...)

for i in range(1, 500):
// wait for the start data marker (two 0's in sequence)
int icount=0;
do
{
  c = serialport.read(size=1)
   if(c==0)
     icount++;
else 
icount=0;
} while(icount<2)
x = serialport.read(size=1)
y = serialport.read(size=1)
z = serialport.read(size=1)
// reset of your code here...

and the arduino code for the above python scriptlet:

void loop () {
serial.print(0,BYTE);
serial.print(0,BYTE);
serial.print(0,BYTE);
Serial.print(analogRead(0)/4, BYTE);
delay (40);
}