# FSR pressure matrix

**URL:** https://discourse.processing.org/t/fsr-pressure-matrix/36582
**Category:** Electronics (Arduino, etc.)
**Created:** [April 25, 2022, 6:20am UTC](https://discourse.processing.org/t/fsr-pressure-matrix/36582 "2022-04-25T06:20:20Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![GalA](https://avatars.discourse-cdn.com/v4/letter/g/a88e57/32.png) [@GalA](https://discourse.processing.org/u/GalA)
#### Post date: [April 25, 2022, 6:20am UTC](https://discourse.processing.org/t/fsr-pressure-matrix/36582/1 "2022-04-25T06:20:20Z")

</div>

Hi all,  
I have a project that I need to manufacture a chair that prevent pressure sores using fsr sensors  
The seat will have 9 fsr sensors and the backrest will have 4 more sensors.  
The sensors are connected to Arduino and the user is presented with a GUI using processing software.  
We have a problem in the GUI.  
The alert system will include two types of alert algorithms. The first is an alert whenever the pressure exceeds the determined pressure threshold, while the second is ​a permanent alert every two hours when the sensors don’t detect change in the pressure which indicates that the user stayed in the same position.  
The equation for the threshold is:  
Pthreshold = (24 / cbrt(1 + 3 \* exp(x))) + 6.5; // Threshold calculation  
The fsr GUI metrix should look like this:  
 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/c/9/c97308635c2a1880ad60a16ddc9d46b4b641094d.png)

I have an Arduino code and I need processing code.  
int fsrPin1 = A0;  
int fsrPin2 = A1;  
int fsrPin3 = A2;  
int fsrPin4 = A3;  
int fsrPin5 = A4;  
int fsrPin6 = A5;  
int fsrReading1;  
int fsrReading2;  
int fsrReading3;  
int fsrReading4;  
int fsrReading5;  
int fsrReading6;  
int fsrVoltage1;  
int fsrVoltage2;  
int fsrVoltage3;  
int fsrVoltage4;  
int fsrVoltage5;  
int fsrVoltage6;  
unsigned long fsrResistance1;  
unsigned long fsrResistance2;  
unsigned long fsrResistance3;  
unsigned long fsrResistance4;  
unsigned long fsrResistance5;  
unsigned long fsrResistance6;  
unsigned long fsrConductance1;

unsigned long fsrConductance2;  
unsigned long fsrConductance3;  
unsigned long fsrConductance4;  
unsigned long fsrConductance5;  
unsigned long fsrConductance6;  
long fsrForce1;  
long fsrForce2;  
long fsrForce3;  
long fsrForce4;  
long fsrForce5;  
long fsrForce6;  
float pressure1;  
float pressure2;  
float pressure3;  
float pressure4;  
float pressure5;  
float pressure6;  
float Pthreshold ;  
int set = 0;  
float t;  
String data = “”;  
unsigned long timer1;

void setup(void) {  
Serial.begin(9600);  
pinMode(fsrPin1, INPUT);  
pinMode(fsrPin2, INPUT);  
pinMode(fsrPin3, INPUT);  
pinMode(fsrPin4, INPUT);  
pinMode(fsrPin5, INPUT);  
pinMode(fsrPin6, INPUT);

}  
void loop(void) {

// Serial.println(“test”);  
fsrReading1 = analogRead(fsrPin1);

fsrReading2 = analogRead (fsrPin2);  
fsrReading3 = analogRead (fsrPin3);  
fsrReading4 = analogRead (fsrPin4);  
fsrReading5 = analogRead (fsrPin5);  
fsrReading6 = analogRead (fsrPin6);

[//Serial.println](https://Serial.println)(fsrReading1);  
fsrVoltage1 = map(fsrReading1, 0, 1023, 0, 5000);  
/\*fsrResistance1 = 5000 - fsrVoltage1; // fsrVoltage is in millivolts so 5V = 5000mV  
fsrResistance1 _= 10000; // 10K resistor  
fsrResistance1 /= fsrVoltage1;_/

// V\_resistor = Vcc \* 10K /(10K + FSR\_resistance  
// FSR\_resistance = Vcc\*10K/(V\_Resistor) - 10K  
if (fsrVoltage1 \> 0)  
{  
fsrResistance1 = 5000.0 \* 10000 / (fsrVoltage1) - 10000;

```
fsrConductance1 = 1000000; // we measure in micromhos
fsrConductance1 /= fsrResistance1;
if (fsrConductance1 <= 1000) {
  fsrForce1 = fsrConductance1 / 80;
} else {
  fsrForce1 = fsrConductance1 - 1000;
  fsrForce1 /= 30;
}

```

}  
else  
{  
fsrResistance1=0;  
fsrConductance1 = 0;  
fsrForce1 = 0;  
}

Serial.println();  
Serial.println("fsrVoltage1 = " + String(fsrVoltage1));  
Serial.println("fsrResistance1 = " + String(fsrResistance1));  
Serial.println("fsrConductance1 = " + String(fsrConductance1));  
Serial.println("fsrForce1 = " + String(fsrForce1));  
Serial.println();  
delay(500);

fsrVoltage2 = map(fsrReading2, 0, 1023, 0, 5000);  
fsrResistance2 = 5000 - fsrVoltage2; // fsrVoltage is in millivolts so 5V = 5000mV  
fsrResistance2 \*= 10000; // 10K resistor  
fsrResistance2 /= fsrVoltage2;  
fsrConductance2 = 1000000; // we measure in micromhos  
fsrConductance2 /= fsrResistance2;  
if (fsrConductance2 \<= 1000) {  
fsrForce2 = fsrConductance2 / 80;  
} else {  
fsrForce2 = fsrConductance2 - 1000;  
fsrForce2 /= 30;

}  
fsrVoltage3 = map(fsrReading3, 0, 1023, 0, 5000);  
fsrResistance3 = 5000 - fsrVoltage3; // fsrVoltage is in millivolts so 5V = 5000mV  
fsrResistance3 \*= 10000; // 10K resistor  
fsrResistance3 /= fsrVoltage3;  
fsrConductance3 = 1000000; // we measure in micromhos  
fsrConductance3 /= fsrResistance3;  
if (fsrConductance3 \<= 1000) {  
fsrForce3 = fsrConductance3 / 80;  
} else {  
fsrForce3 = fsrConductance3 - 1000;  
fsrForce3 /= 30;  
}  
fsrVoltage4 = map(fsrReading4, 0, 1023, 0, 5000);  
fsrResistance4 = 5000 - fsrVoltage4; // fsrVoltage is in millivolts so 5V = 5000mV  
fsrResistance4 \*= 10000; // 10K resistor  
fsrResistance4 /= fsrVoltage4;  
fsrConductance4 = 1000000; // we measure in micromhos  
fsrConductance4 /= fsrResistance4;  
if (fsrConductance4 \<= 1000) {  
fsrForce4 = fsrConductance4 / 80;  
} else {  
fsrForce4 = fsrConductance4 - 1000;  
fsrForce4 /= 30;  
}  
fsrVoltage5 = map(fsrReading5, 0, 1023, 0, 5000);  
fsrResistance5 = 5000 - fsrVoltage5; // fsrVoltage is in millivolts so 5V = 5000mV

fsrResistance5 \*= 10000; // 10K resistor  
fsrResistance5 /= fsrVoltage5;  
fsrConductance5 = 1000000; // we measure in micromhos  
fsrConductance5 /= fsrResistance5;  
if (fsrConductance5 \<= 1000) {  
fsrForce5 = fsrConductance5 / 80;  
} else {  
fsrForce5 = fsrConductance5 - 1000;  
fsrForce5 /= 30;  
}  
fsrVoltage6 = map(fsrReading6, 0, 1023, 0, 5000);  
fsrResistance6 = 5000 - fsrVoltage6; // fsrVoltage is in millivolts so 5V = 5000mV  
fsrResistance6 \*= 10000; // 10K resistor  
fsrResistance6 /= fsrVoltage6;  
fsrConductance6 = 1000000; // we measure in micromhos  
fsrConductance6 /= fsrResistance6;  
if (fsrConductance6 \<= 1000) {  
fsrForce6 = fsrConductance6 / 80;  
} else {  
fsrForce6 = fsrConductance6 - 1000;  
fsrForce6 /= 30;  
}  
// Calculation pressure [kPa]  
pressure1 = fsrForce1 \* 1.9745;  
pressure2 = fsrForce3 \* 1.9745;  
pressure3 = fsrForce4 \* 1.9745;  
pressure4 = fsrForce5 \* 1.9745;  
pressure5 = fsrForce6 \* 1.9745;

if ((pressure1 \> 0 || pressure2 \> 0 || pressure3 \> 0 || pressure4 \> 0 || pressure5 \> 0 || pressure6 \> 0) && set == 0) {  
set = 1;  
timer1 = millis();  
}  
else {  
set = 0;  
timer1 = millis();  
Pthreshold = 0;  
}  
long c = timer1 / 1000;  
t = float (c) / 60; // Conversion to minutes  
float x = (t - 74) / 4;  
Pthreshold = (24 / cbrt(1 + 3 \* exp(x))) + 6.5; // Threshold calculation

/_data = String(pressure1) + “,” + String(pressure2) + “,” + String(pressure3) + “,” + String(pressure4) + “,” +  
String(pressure5) + “,” + String(Pthreshold);_/

data = String(fsrReading1) + “,” + String(pressure2) + “,” + String(pressure3) + “,” + String(pressure4) + “,” +  
String(pressure5) + “,” + String(Pthreshold);  
Serial.println(data);  
delay(1000);  
}

**pls help me! I need to submit this project ASAP.**

---

<div class="post-metadata">

### Author: ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)
#### Post date: [April 26, 2022, 6:44am UTC](https://discourse.processing.org/t/fsr-pressure-matrix/36582/2 "2022-04-26T06:44:34Z")

</div>

Hi

This is how to connect Arduino with processing

Try to send at first one sensor value

> **[How to Make Arduino and Processing IDE Communicate  | Arduino](https://maker.pro/arduino/tutorial/how-to-make-arduino-and-processing-ide-communicate)**
>
> Learn how to connect the Arduino to the Processing IDE so they can communicate with one another.

---

<div class="post-metadata">

### Author: ![GalA](https://avatars.discourse-cdn.com/v4/letter/g/a88e57/32.png) [@GalA](https://discourse.processing.org/u/GalA)
#### Post date: [April 26, 2022, 7:06am UTC](https://discourse.processing.org/t/fsr-pressure-matrix/36582/3 "2022-04-26T07:06:24Z")

</div>

Hi  
I tried to write a processing code but it doesn’t show the colors according to the pressure. This the code:

import processing.serial.\*;  
Serial port;  
String[] mysensors = {"", “”, “”, “”, “”, “”, “”, “”, “”, “”};  
String data="";  
int x = 420;  
int y = 500;  
int x1=950;  
int y1=750;  
float[] d = {0, 0, 0, 0, 0};  
float[] T = {0, 0, 0, 0, 0};  
int r1=0, g1=0, b1=102;  
int r2=0, g2=0, b2=102;  
int r3=0, g3=0, b3=102;  
int r4=0, g4=0, b4=102;  
int r5=0, g5=0, b5=102;  
int r6=0, g6=0, b6=102;  
int p=0;  
int[] c={0, 0, 0, 0, 0};  
void setup() {  
size(950, 750);  
port = new Serial (this, “COM3”, 9600);  
port.write(0);  
port.bufferUntil(’\n’);  
}  
void draw() {  
background(0);  
fill(0, 0, 102);

rect(0, 0, x1, 30);  
stroke(0, 0, 102);  
strokeWeight(4);  
line(0, 95, x1, 95); //first horizontal line  
line(0, 380, x1, 380); //first horizontal line  
fill(102, 204, 255);  
textSize(28);  
text(“Mattress for mapping and optimizing pressure for bedridden patients”, 0, 80, -30);  
textSize(32);  
text(“Pressure Map”, 365, 430, -30);  
noStroke();  
text((“Pressure1 : “+mysensors[0]+” kPa”), 10, 150);  
text((“Pressure2 : “+mysensors[1]+” kPa”), 380, 150);  
text((“Pressure3 : “+mysensors[2]+” kPa”), 10, 210);  
text((“Pressure4 : “+mysensors[3]+” kPa”), 380, 210);  
text((“Pressure5 : “+mysensors[4]+” kPa”), 10, 270);  
text((“Pressure6 : “+ mysensors[5] +” kPa”), 380, 270);  
fill( 0, 0, 102); //dark blue  
rect(650, 650, 50, 15);  
fill(0, 0, 204); //light blue  
rect(650, 630, 50, 15);  
fill(102, 204, 255); //more light blue  
rect(650, 610, 50, 15);  
fill(0, 153, 0); //green  
rect(650, 590, 50, 15);  
fill(153, 255, 153); //light green  
rect(650, 570, 50, 15);

fill(255, 255, 102); //yellow  
rect(650, 550, 50, 15);  
fill(255, 204, 0); //bright1  
rect(650, 530, 50, 15);  
fill(255, 0, 0); //red  
rect(650, 510, 50, 15);  
fill(204, 51, 0); //dark color  
rect(650, 490, 50, 15);  
fill( r1, g1, b1);  
ellipse(x+(55_0), y, 55, 55);  
fill( r2, g2, b2);  
ellipse(x+(55_1), y, 55, 55);  
fill( r3, g3, b3);  
ellipse(x+(55_0), y+(55_1), 55, 55);  
fill( r4, g4, b4);  
ellipse(x+(55_1), y+(55_1), 55, 55);  
fill( r5, g5, b5);  
ellipse(x+(55_0),y+(55_2), 55, 55);  
fill( r6, g6, b6);  
ellipse(x+(55_1), y+(55_2), 55, 55);  
}  
void serialEvent ( Serial myPort) {  
try {  
while (myPort.available() \> 0) {  
data = myPort.readStringUntil(’\n’);  
if (data != null)  
{  
data= trim(data);

mysensors = split(data, ‘,’);  
}  
}  
for (int i = 0; i \<5; i++) {  
d[i]=float(mysensors[i]);  
print(d[i]+" “);  
}  
for (int i = 0; i \<5; i++) {  
T[i]=float(mysensors[5+i]);  
print(T[i]+” “);  
}  
println(”");  
for (int i=0; i \< 5; i++) {  
c[i] = int((d[i]\*9)/T[i]);  
}  
selectColor1();  
selectColor2();  
selectColor3();  
selectColor4();  
selectColor5();  
}  
catch (Exception e) {  
println(“Initialization exception”);  
// decide what to do here  
}  
}

void selectColor1() {  
if (d[0] \> T[0]) {  
r1=255;  
g1=0;  
b1=0;  
} else if (c[0]==0) {  
r1=0;  
g1=0;  
b1=102;  
} else if (c[0]==1) {  
r1=0;  
g1=0;  
b1=204;  
} else if (c[0]==2) {  
r1=102;  
g1=204;  
b1=255;  
} else if (c[0]==3) {  
r1=0;  
g1=153;  
b1=0;  
} else if (c[0]==4) {  
r1=153;  
g1=255;  
b1=153;  
} else if (c[0]==5) {  
r1=255;  
g1=255;  
b1=102;  
} else if (c[0]==6) {  
r1=255;  
g1=204;

b1=0;  
} else if (c[0]==7) {  
r1=255;  
g1=0;  
b1=0;  
} else if (c[0]==8) {  
r1=204;  
g1=51;  
b1=0;  
}  
}  
void selectColor2() {  
if (d[1] \> T[1]) {  
r2=255;  
g2=0;  
b2=0;  
} else if (c[1]==0) {  
r2=0;  
g2=0;  
b2=102;  
} else if (c[1]==1) {  
r2=0;  
g2=0;  
b2=204;  
} else if (c[1]==2) {  
r2=102;  
g2=204;  
b2=255;  
} else if (c[1]==3) {  
r2=0;  
g2=153;

b2=0;  
} else if (c[1]==4) {  
r2=153;  
g2=255;  
b2=153;  
} else if (c[1]==5) {  
r2=255;  
g2=255;  
b2=102;  
} else if (c[1]==6) {  
r2=255;  
g2=204;  
b2=0;  
} else if (c[1]==7) {  
r2=255;  
g2=0;  
b2=0;  
} else if (c[1]==8) {  
r2=204;  
g2=51;  
b2=0;  
}  
}  
void selectColor3() {  
if (d[2] \> T[2]) {  
r3=255;  
g3=0;  
b3=0;  
} else if (c[2]==0) {  
r3=0;  
g3=0;

b3=102;  
} else if (c[2]==1) {  
r3=0;  
g3=0;  
b3=204;  
} else if (c[2]==2) {  
r3=102;  
g3=204;  
b3=255;  
} else if (c[2]==3) {  
r3=0;  
g3=153;  
b3=0;  
} else if (c[2]==4) {  
r3=153;  
g3=255;  
b3=153;  
} else if (c[2]==5) {  
r3=255;  
g3=255;  
b3=102;  
} else if (c[2]==6) {  
r3=255;  
g3=204;  
b3=0;  
} else if (c[2]==7) {  
r3=255;  
g3=0;  
b3=0;  
} else if (c[2]==8) {  
r3=204;  
g3=51;

b3=0;  
}  
}  
void selectColor4() {  
if (d[3] \> T[3]) {  
r4=255;  
g4=0;  
b4=0;  
} else if (c[3]==0) {  
r4=0;  
g4=0;  
b4=102;  
} else if (c[3]==1) {  
r4=0;  
g4=0;  
b4=204;  
} else if (c[3]==2) {  
r4=102;  
g4=204;  
b4=255;  
} else if (c[3]==3) {  
r4=0;  
g4=153;  
b4=0;  
} else if (c[3]==4) {  
r4=153;  
g4=255;  
b4=153;  
} else if (c[3]==5) {  
r4=255;  
g4=255;

b4=102;  
} else if (c[3]==6) {  
r4=255;  
g4=204;  
b4=0;  
} else if (c[3]==7) {  
r4=255;  
g4=0;  
b4=0;  
} else if (c[3]==8) {  
r4=204;  
g4=51;  
b4=0;  
}  
}  
void selectColor5() {  
if (d[4] \> T[4]) {  
r5=255;  
g5=0;  
b5=0;  
} else if (c[4]==0) {  
r5=0;  
g5=0;  
b5=102;  
} else if (c[4]==1) {  
r5=0;  
g5=0;  
b5=204;  
} else if (c[4]==2) {  
r5=102;  
g5=204;

b5=255;  
} else if (c[4]==4) {  
r5=0;  
g5=153;  
b5=0;  
} else if (c[4]==4) {  
r5=153;  
g5=255;  
b5=153;  
} else if (c[4]==5) {  
r5=255;  
g5=255;  
b5=102;  
} else if (c[4]==6) {  
r5=255;  
g5=204;  
b5=0;  
} else if (c[4]==7) {  
r5=255;  
g5=0;  
b5=0;  
} else if (c[4]==8) {  
r5=204;  
g5=51;  
b5=0;  
}  
}

---

<div class="post-metadata">

### Author: ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)
#### Post date: [April 26, 2022, 7:21am UTC](https://discourse.processing.org/t/fsr-pressure-matrix/36582/4 "2022-04-26T07:21:37Z")

</div>

In void selectColor use print to check what you are receiving

---

<div class="post-metadata">

### Author: ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)
#### Post date: [April 26, 2022, 7:27am UTC](https://discourse.processing.org/t/fsr-pressure-matrix/36582/5 "2022-04-26T07:27:04Z")

</div>

Format your code using  
\<√\>

 ![Screenshot_2022-04-26-10-24-24-878](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/b/e/befb56ce4be00aa2b377bfe621eb416c4b2538fa.jpeg)

---

<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: [April 26, 2022, 11:33am UTC](https://discourse.processing.org/t/fsr-pressure-matrix/36582/6 "2022-04-26T11:33:18Z")

</div>

Hello @GalA ,

Welcome aboard!

Please format your code as a courtesy to the community:  
[https://discourse.processing.org/faq#format-your-code](https://discourse.processing.org/faq#format-your-code)

Please only post an MCVE:

- [How to create a Minimal, Reproducible Example - Help Center - Stack Overflow](https://stackoverflow.com/help/minimal-reproducible-example)
- [Guidelines—Asking Questions](https://discourse.processing.org/t/guidelines-asking-questions/2147#is-your-problem-isolated-3)

I will test this out once you simplify and format it and I can copy it without errors.

`:)`

---

<div class="post-metadata">

### Author: ![RichardDL](https://avatars.discourse-cdn.com/v4/letter/r/f475e1/32.png) [@RichardDL](https://discourse.processing.org/u/RichardDL)
#### Post date: [April 26, 2022, 7:49pm UTC](https://discourse.processing.org/t/fsr-pressure-matrix/36582/7 "2022-04-26T19:49:50Z")

</div>

Hi @GalA, " **I need to submit this project ASAP.**" - I hope you have time to think about some improvements. At the moment several aspects of the code make it look like a rushed job without the time and study to understand programming principles and avoid errors. Suggestions:

The functions selectColor1…5 are identical except for the arrayindex and the rgbX vars used. Change selectColor1 to selectColor which accepts a parameter 0…4, this becomes the index to the array. Change the vars r1…b5 to 3 arrays. Now delete selectColor2…4 (Less code, neater, easier to work with.)

Don’t use single character variable names, no help to the reader, hard to search the code because the search finds other uses of the letter. r → red or colrRed.

Use String.format to fix the size of the text, stops it moving around depending on value. (Might have to adjust as I can’t see your value strings.) This also gives the possibility of using one display line with a loop.

```auto
old: text((“Pressure1 : “+mysensors[0]+” kPa”), 10, 150);
new: ix = 0; text((String.format("Pressure %1d : %-12s kPa", ix+1, mysensors[ix])), 10, 150);

```

Where you have 3 loops 0…5 near line 93, you could have just 1 loop with all 6 action lines in that. Merge both prints into a String.format and the output will be more regular and easier to read.

You could go further with the colours, using vars of type color instead of r,g,b. You might like an array,  
and that simplifies selectColor, and where you use the colour becomes fill(pressureColours[ix])

```auto
color pressureColours[] = new color[6];
void setup() {
pressureColours[0] = color(255,0,0);
...

```

Hope this helps.

---

<div class="post-metadata">

### Author: ![GalA](https://avatars.discourse-cdn.com/v4/letter/g/a88e57/32.png) [@GalA](https://discourse.processing.org/u/GalA)
#### Post date: [May 7, 2022, 8:51am UTC](https://discourse.processing.org/t/fsr-pressure-matrix/36582/9 "2022-05-07T08:51:27Z")

</div>

Thanks for your help!

```auto

import processing.serial.*;
Serial port;
String[] mysensors = {"", "", "", "", "", "", "", "", "", ""};
String data="";
int x = 420;
int y = 500;
int x1=950;
int y1=750;
float[] d = {0, 0, 0, 0, 0};
float[] T = {0, 0, 0, 0, 0};
int r1=0, g1=0, b1=102;
int r2=0, g2=0, b2=102;
int r3=0, g3=0, b3=102;
int r4=0, g4=0, b4=102;
int r5=0, g5=0, b5=102;
int r6=0, g6=0, b6=102;
int p=0;
int[] c={0, 0, 0, 0, 0};
void setup() {
size(950, 750);
port = new Serial (this, "COM3", 9600);
port.write(0);
port.bufferUntil('\n');
}
void draw() {
background(0);
fill(0, 0, 102);

rect(0, 0, x1, 30);
stroke(0, 0, 102);
strokeWeight(4);
line(0, 95, x1, 95); //first horizontal line
line(0, 380, x1, 380); //first horizontal line
fill(102, 204, 255);
textSize(28);
text("Mattress for mapping and optimizing pressure for bedridden patients", 0, 80, -30);
textSize(32);
text("Pressure Map", 365, 430, -30);
noStroke();
text(("Pressure1 : "+mysensors[0]+" kPa"), 10, 150);
text(("Pressure2 : "+mysensors[1]+" kPa"), 380, 150);
text(("Pressure3 : "+mysensors[2]+" kPa"), 10, 210);
text(("Pressure4 : "+mysensors[3]+" kPa"), 380, 210);
text(("Pressure5 : "+mysensors[4]+" kPa"), 10, 270);
text(("Pressure6 : "+ mysensors[5] +" kPa"), 380, 270);
fill( 0, 0, 102); //dark blue
rect(650, 650, 50, 15);
fill(0, 0, 204); //light blue
rect(650, 630, 50, 15);
fill(102, 204, 255); //more light blue
rect(650, 610, 50, 15);
fill(0, 153, 0); //green
rect(650, 590, 50, 15);
fill(153, 255, 153); //light green
rect(650, 570, 50, 15);

fill(255, 255, 102); //yellow
rect(650, 550, 50, 15);
fill(255, 204, 0); //bright1
rect(650, 530, 50, 15);
fill(255, 0, 0); //red
rect(650, 510, 50, 15);
fill(204, 51, 0); //dark color
rect(650, 490, 50, 15);
fill( r1, g1, b1);
ellipse(x+(55*0), y, 55, 55);
fill( r2, g2, b2);
ellipse(x+(55*1), y, 55, 55);
fill( r3, g3, b3);
ellipse(x+(55*0), y+(55*1), 55, 55);
fill( r4, g4, b4);
ellipse(x+(55*1), y+(55*1), 55, 55);
fill( r5, g5, b5);
ellipse(x+(55*0),y+(55*2), 55, 55);
fill( r6, g6, b6);
ellipse(x+(55*1), y+(55*2), 55, 55);
}
void serialEvent ( Serial myPort) {
try {
while (myPort.available() > 0) {
data = myPort.readStringUntil('\n');
if (data != null)
{
data= trim(data);

mysensors = split(data, ',');
}
}
for (int i = 0; i <5; i++) {
d[i]=float(mysensors[i]);
print(d[i]+" ");
}
for (int i = 0; i <5; i++) {
T[i]=float(mysensors[5+i]);
print(T[i]+" ");
}
println("");
for (int i=0; i < 5; i++) {
c[i] = int((d[i]*9)/T[i]);
}
selectColor1();
selectColor2();
selectColor3();
selectColor4();
selectColor5();
}
catch (Exception e) {
println("Initialization exception");
// decide what to do here
}
}

void selectColor1() {
if (d[0] > T[0]) {
r1=255;
g1=0;
b1=0;
} else if (c[0]==0) {
r1=0;
g1=0;
b1=102;
} else if (c[0]==1) {
r1=0;
g1=0;
b1=204;
} else if (c[0]==2) {
r1=102;
g1=204;
b1=255;
} else if (c[0]==3) {
r1=0;
g1=153;
b1=0;
} else if (c[0]==4) {
r1=153;
g1=255;
b1=153;
} else if (c[0]==5) {
r1=255;
g1=255;
b1=102;
} else if (c[0]==6) {
r1=255;
g1=204;

b1=0;
} else if (c[0]==7) {
r1=255;
g1=0;
b1=0;
} else if (c[0]==8) {
r1=204;
g1=51;
b1=0;
}
}
void selectColor2() {
if (d[1] > T[1]) {
r2=255;
g2=0;
b2=0;
} else if (c[1]==0) {
r2=0;
g2=0;
b2=102;
} else if (c[1]==1) {
r2=0;
g2=0;
b2=204;
} else if (c[1]==2) {
r2=102;
g2=204;
b2=255;
} else if (c[1]==3) {
r2=0;
g2=153;

b2=0;
} else if (c[1]==4) {
r2=153;
g2=255;
b2=153;
} else if (c[1]==5) {
r2=255;
g2=255;
b2=102;
} else if (c[1]==6) {
r2=255;
g2=204;
b2=0;
} else if (c[1]==7) {
r2=255;
g2=0;
b2=0;
} else if (c[1]==8) {
r2=204;
g2=51;
b2=0;
}
}
void selectColor3() {
if (d[2] > T[2]) {
r3=255;
g3=0;
b3=0;
} else if (c[2]==0) {
r3=0;
g3=0;

b3=102;
} else if (c[2]==1) {
r3=0;
g3=0;
b3=204;
} else if (c[2]==2) {
r3=102;
g3=204;
b3=255;
} else if (c[2]==3) {
r3=0;
g3=153;
b3=0;
} else if (c[2]==4) {
r3=153;
g3=255;
b3=153;
} else if (c[2]==5) {
r3=255;
g3=255;
b3=102;
} else if (c[2]==6) {
r3=255;
g3=204;
b3=0;
} else if (c[2]==7) {
r3=255;
g3=0;
b3=0;
} else if (c[2]==8) {
r3=204;
g3=51;

b3=0;
}
}
void selectColor4() {
if (d[3] > T[3]) {
r4=255;
g4=0;
b4=0;
} else if (c[3]==0) {
r4=0;
g4=0;
b4=102;
} else if (c[3]==1) {
r4=0;
g4=0;
b4=204;
} else if (c[3]==2) {
r4=102;
g4=204;
b4=255;
} else if (c[3]==3) {
r4=0;
g4=153;
b4=0;
} else if (c[3]==4) {
r4=153;
g4=255;
b4=153;
} else if (c[3]==5) {
r4=255;
g4=255;

b4=102;
} else if (c[3]==6) {
r4=255;
g4=204;
b4=0;
} else if (c[3]==7) {
r4=255;
g4=0;
b4=0;
} else if (c[3]==8) {
r4=204;
g4=51;
b4=0;
}
}
void selectColor5() {
if (d[4] > T[4]) {
r5=255;
g5=0;
b5=0;
} else if (c[4]==0) {
r5=0;
g5=0;
b5=102;
} else if (c[4]==1) {
r5=0;
g5=0;
b5=204;
} else if (c[4]==2) {
r5=102;
g5=204;

b5=255;
} else if (c[4]==4) {
r5=0;
g5=153;
b5=0;
} else if (c[4]==4) {
r5=153;
g5=255;
b5=153;
} else if (c[4]==5) {
r5=255;
g5=255;
b5=102;
} else if (c[4]==6) {
r5=255;
g5=204;
b5=0;
} else if (c[4]==7) {
r5=255;
g5=0;
b5=0;
} else if (c[4]==8) {
r5=204;
g5=51;
b5=0;
}
}

```

---

<div class="post-metadata">

### Author: ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)
#### Post date: [May 7, 2022, 11:52am UTC](https://discourse.processing.org/t/fsr-pressure-matrix/36582/10 "2022-05-07T11:52:24Z")

</div>

> [@Using two different readStringUntil "characters"](https://discourse.processing.org/t/using-two-different-readstringuntil-characters/10769/6):
>
> The solution I gave on that link expects the Arduino C code to send the multi-data as if they were a row of tab-separated values (TSV): face_with_monocle That is, each value is followed by a \t character; except last 1, which is followed by an \n instead: nerd_face Serial.print(temperature); Serial.write('\t'); Serial.print(masse); Serial.write('\t'); Serial.print(humidite); Serial.write('\t'); Serial.print(comptage); Serial.write('\t'); Serial.println(son); // implies '\n' At the Pro…
