Yup, it was what I wanted. So, for the sake of sharing, here's what I did with it. I wan to control something with two sets of sensors on the floor. The problem was that somebody could step on two adjacent "keys" (the sensors are actually a keyboard board rewired) or step on a key and tap the other etc.
Anyway, here is my solution. You'll notice that almost everything is in pairs, that's because I have 2 sets of sensors.
Code:
String stringP1 = "1234567890-=";
String stringP2 = "qwertyuiop[]";
PFont font;
String st;
int[] keysPressed1 = new int[13];
int[] keysPressed2 = new int[13];
int num;
void setup(){
size(640,480,P3D);
background(255);
fill(0);
}
void draw(){
int temp1=0, temp2=0, tempNum=0;
background(255);
for (int i=0;i<stringP1.length();i++) {
if (keysPressed1[i] != 0){
temp1 += keysPressed1[i];
tempNum++;
}
}
if (tempNum>0) temp1 = temp1 / tempNum;
tempNum=0;
for (int i=0;i<stringP2.length();i++) {
if (keysPressed2[i] != 0){
temp2 +=keysPressed2[i];
tempNum++;
}
}
if (tempNum>0) temp2 = temp2 / tempNum;
rect(temp2, height-10, 110, 10);
rect(temp1, 0, 110, 10);
}
void keyPressed() {
num = stringP1.indexOf(key);
st = str(key);
if (num >= 0) keysPressed1[num] = getValue(stringP1, st, 1, 540);
num = stringP2.indexOf(key);
st = str(key);
if (num >= 0) keysPressed2[num] = getValue(stringP2, st, 1, 540);
}
void keyReleased() {
num = stringP1.indexOf(key);
if (num >= 0) keysPressed1[num] = 0;
num = stringP2.indexOf(key);
if (num >= 0) keysPressed2[num] = 0;
}
void mousePressed(){
}
int getValue(String myString, String myKey, int mapMin, int mapMax){
float pos = myString.indexOf(myKey);
float maxPos = myString.length()-1;
return round( mapMin+(pos/maxPos)*(mapMax-mapMin) );
}