// Accelerometer Remote Colour Selection and Drawing
// Hannah Johnston
// May 2007
import procontroll.*;
import java.io.*;
ControllIO controll;
color userColour;
float paintX = 200;
float paintY = 200;
ControllSlider sliderX, sliderY, sliderZ;
ControllButton button0, button1;
float totalX = 0, totalY = 0, totalZ = 0;
void setup(){
size(400,400);
smooth();
background(0);
colorMode(HSB, 4);
controll = ControllIO.getInstance(this);
controll.printDevices();
Change the device name when using a different device
ControllDevice device = controll.getDevice(”Seng”);
// Using slider x, y, z to get the accelerometer value
// The slider values don’t correspond on the same scale as those used in C
// There is no calibration here yet either
sliderX = device.getSlider(2);
sliderY = device.getSlider(1);
sliderZ = device.getSlider(0);
button0 = device.getButton(0);
button1 = device.getButton(1);
}
int arrayindex = 0;
void draw()
{
float myX, myY;
// Multiplied by a fairly arbitrary value to get it into the 0-4 range
totalX = sliderX.getValue()*20;
totalY = sliderY.getValue()*15;
totalZ = sliderZ.getValue()*10;
println(” ” + totalX + ” ” + totalY + ” ” + totalZ);
float x = totalX;
float y = totalY;
float z = totalZ;
// Left Button: Draw with the current tool selection
// Hold it down when drawing
if(button0.pressed()==true){
int i=0;
myX = sliderX.getValue()*10;
myY = sliderY.getValue()*10;
paintX += myX;
paintY += myY;
fill(userColour);
ellipse(paintX, paintY, 10, 10);
println(”Painting ” + paintX + ” ” + paintY);
i++;
}
// Right Button: Clear screen (it gets messy)
else if(button1.pressed()==true){
fill(0);
rect( 0, 0, 400, 400 );
}
// No Button Press: Display the colour-picker rectangle
else{
noStroke();
userColour = color(abs(x), abs(y), abs(z));
fill(userColour);
rect(340, 340, 50, 50);
}
}