Lo so che andrebbe resettata la schermata ma la schermata carica una foto e quindi non credo sia possibile resettarla.
In più acquisisce dati con un ciclo "if" per gestire più sensori.
Comunque ecco il codice cosi diventa più chiaro.
C'è anche lo script per pulire la seriale e sembra che funzioni
Scusate per il copia incolla ma non mi ricordo come si pubblica. (non uccidetemi)
import processing.serial.*;
PImage img; // Dichiaro la variabile per caricare lo sfondo
PFont f; // Dichiaro la variabile per i caratteri di scrittura
Serial myPort; // Dichiaro la variabile per la porta seriale
int xPos1 = 1; // Dichiaro le variabili per il cursore del grafico
float yPosOld1 =1;
int xPos2 = 1; // Dichiaro le variabili per il cursore del grafico
float yPosOld2 =1;
int d = 30;
int p1 = d;
int p2 = p1+d;
int p3 = p2+d;
int p4 = 950;
float inByte1;
float inByte2;
int T_mandata;
int T_esterna;
void setup() {
size(1100, 700); // grandezza del display
img = loadImage("sfondo grafico caldaia.JPG"); // Carico l'immagine nel display
printArray(PFont.list()); // carico il font per il titolo
f = createFont("Calibri", 20);
textFont(f);
println (Serial. list());
myPort = new Serial (this, "COM8",9600); // dichiaro la porta di comunicazione dati
image(img,0, 0,img.width2.2, img.height2.2);
textAlign(CENTER);
drawType(width * 0.02);
}
void draw()
{
}
void drawType(float x)
{
fill(0);
text("GRAFICO DELLE TEMPERATURE", 500, 30);
text("-10°C", 1031,640);
text(" 0°C", 1030,580);
text("10°C", 1030,520);
text("20°C", 1030,460);
text("30°C", 1030,400);
text("40°C", 1030,340);
text("50°C", 1030,280);
text("60°C", 1030,220);
text("70°C", 1030,160);
text("Temperatura mandata impianto",800,100);
text("°C",980,100);
text("Temperatura esterna",845,80);
text("°C",980,80);
line(x, 0, x, 800);
line(p1, 640, p4, 640);
line(p1, 580, p4, 580);
line(p1, 520, p4, 520);
line(p1, 460, p4, 460);
line(p1, 400, p4, 400);
line(p1, 340, p4, 340);
line(p1, 280, p4, 280);
line(p1, 220, p4, 220);
line(p1, 160, p4, 160);
strokeWeight(1);
}
void serialEvent (Serial myPort)
{
String inString = myPort.readStringUntil('\n');
if (inString != null)
{
inString = trim(inString);
float inByte = float (inString);
int temperatura = int(inString);
if(inByte>500)
{
fill(200);
text(T_esterna,960,80);
T_esterna = (temperatura-1000);
fill(0);
text(T_esterna,960,80);
inByte1=(inByte-982)*10;
inByte1 = map (inByte1,0,1023,0, height);
stroke (255,0,0);
strokeWeight(2);
line(xPos1, height - yPosOld1, xPos1, height - inByte1);
}
else
{
fill(200);
text(T_mandata,960,100);
T_mandata = temperatura;
fill(0);
text(T_mandata,960,100);
inByte2=(inByte+14)*10;
inByte2 = map (inByte2,0,1023,0, height);
stroke (0,0,0);
strokeWeight(2);
line(xPos2, height - yPosOld2, xPos2, height - inByte2);
}
if (xPos1 >= 1000 && xPos2 >= 1000)
{
xPos1 = 0;
xPos2 = 0;
myPort.clear(); // pulizia del buffer seriale
image(img,0, 0,img.width2.2, img.height2.2);
textAlign(CENTER);
drawType(width * 0.02);
}
else
xPos1++;
xPos2++;
yPosOld1 = inByte1;
yPosOld2 = inByte2;
}
}