To save others the trouble:
class Sensors{
/* Attributes of a sensor including min and max values which will be
obtained during calibration. */
int value;
int minValue = 1023;
int maxValue = 0;
/* Scales the operation interval of each sensor so that we will not have
to fine tune the software each time and the sensors will interchangable. */
int scaledValue(){
return int(constrain(map(value, minValue, maxValue, 0, 127), 0, 127));
}
}
///////////////////////////////////////////////////////////
import processing.serial.*;
import cc.arduino.*;
import oscP5.*;
import netP5.*;
OscP5 informant;
NetAddress remoteLocation;
Sensors[] sensorler = new Sensors[6];
Arduino arduino;
////////////////////////////////////////////////////////////
void setup(){
// size(600, 400);
size(50, 50);
frameRate(15);
informant = new OscP5(this, 5000);
remoteLocation = new NetAddress("127.0.0.1", 6000);
arduino = new Arduino(this, Arduino.list()[0], 115200);
for(int i = 0; i < 6; i++){
sensorler[i] = new Sensors();
}
/* Calibration code starts here. Since it takes a bit of time before the
sensor values are received from the arduino, we wait for 5 seconds before
the calibration starts. For the next 10 seconds, imteract with the sensors
so that the program will gather the minimum and maximum values and assign
them to corresponding objects. */
while(millis()< 5000){}
println("Calibration start");
while(millis() < 15000){
for(int i = 0; i < 6; i++){
sensorler[i].value = arduino.analogRead(i);
if(sensorler[i].value > sensorler[i].maxValue)
sensorler[i].maxValue = sensorler[i].value;
if(sensorler[i].value < sensorler[i].minValue)
sensorler[i].minValue = sensorler[i].value;
}
}
println("Calibration over");
}
///////////////////////////////////////////////////////////
void draw(){
/* Read new values from Arduino for each loop of draw(). */
for(int i = 0; i < 6; i++){
sensorler[i].value = arduino.analogRead(i);
{
OscMessage messageToRemoteLocation = new OscMessage("/R1");
messageToRemoteLocation.add(sensorler[0].scaledValue());
informant.send(messageToRemoteLocation, remoteLocation);
}
{
OscMessage messageToRemoteLocation = new OscMessage("/R2");
messageToRemoteLocation.add(sensorler[1].scaledValue());
informant.send(messageToRemoteLocation, remoteLocation);
}
{
OscMessage messageToRemoteLocation = new OscMessage("/R3");
messageToRemoteLocation.add(sensorler[2].scaledValue());
informant.send(messageToRemoteLocation, remoteLocation);
}
{
OscMessage messageToRemoteLocation = new OscMessage("/Sharp");
messageToRemoteLocation.add(sensorler[3].scaledValue());
informant.send(messageToRemoteLocation, remoteLocation);
}
{
OscMessage messageToRemoteLocation = new OscMessage("/y");
messageToRemoteLocation.add(sensorler[4].scaledValue());
informant.send(messageToRemoteLocation, remoteLocation);
}
{
OscMessage messageToRemoteLocation = new OscMessage("/x");
messageToRemoteLocation.add(sensorler[5].scaledValue());
informant.send(messageToRemoteLocation, remoteLocation);
}
}
// println("R1-" + sensorler[0].scaledValue() + "***R2-" + sensorler[1].scaledValue() +
// "***R3-" + sensorler[2].scaledValue() + "***Sharp-" + sensorler[3].scaledValue() +
// "***Y-" + sensorler[4].scaledValue() + "***X-" + sensorler[5].scaledValue());
//
//
// /* Drawing the RGB rectangles that visualize the sensor inputs. */
// noStroke();
//
// fill(sensorler[0].scaledValue(), 0, 0, sensorler[0].scaledValue());
// rect(0, 0, 100, 400);
//
// fill(0, sensorler[1].scaledValue(), 0, sensorler[1].scaledValue());
// rect(100, 0, 100, 400);
//
// fill(0, 0, sensorler[2].scaledValue(), sensorler[2].scaledValue());
// rect(200, 0, 100, 400);
//
// fill(0, 0, sensorler[3].scaledValue(), sensorler[3].scaledValue());
// rect(300, 0, 100, 400);
//
// fill(0, 0, sensorler[4].scaledValue(), sensorler[4].scaledValue());
// rect(400, 0, 100, 400);
//
// fill(0, 0, sensorler[5].scaledValue(), sensorler[5].scaledValue());
// rect(500, 0, 100, 400);
}
my sketch give error
What error?
How to use this forum