And here is my sketch I'm working on.
I haven't done any work on the graph yet, but any advice is much appreciated.
I'm sure there are easier ways and clean ways to do many of these functions. But I've just started to use processing.
Code://import Serial communication library
import processing.serial.*;
//init variables
int startSECOND, startMINUTE, startTOTAL;
int stopSECOND, stopMINUTE, stopTOTAL;
int dis_m, dis_s;
boolean startcount = false;
Serial commPort;
float tempC;
float tempF;
float tempB;
float tempEnvF;
PFont font12;
PFont font24;
PFont font18;
PFont font7;
PFont font10;
void setup()
{
//setup fonts for use throughout the application
font12 = loadFont("Verdana-12.vlw");
font24 = loadFont("Verdana-24.vlw");
font18 = loadFont("Verdana-18.vlw");
font7 = loadFont("Verdana-7.vlw");
font10 = loadFont("Verdana-10.vlw");
//set the size of the window
size(680, 600);
//init serial communication port
commPort = new Serial(this, Serial.list()[1], 9600);
}
void draw()
{
//get the temp from the serial port
while (commPort.available() > 0)
{
tempC = commPort.read();
tempB = commPort.read();
//refresh the background to clear old data
background(#7683b4);
//draw graph
stroke(0); //graph is 375 pixels high - 1 px for each degree
fill(255,255,255); // of F from 225 F to 500F
rect(30,145,500,375); //graph is 500pixels wide - 25 pixels for each
//minute, from 0 to 20 minutes
//write reference values for temp
fill(0,0,0);
textFont(font7);
textAlign(RIGHT);
text("500 F", 28, 145);
line(28,145,29,145);
text("475 F",28,170);
line(28,170,29,170);
text("450 F",28,195);
line(28,195,29,195);
text("425 F",28,220);
line(28,220,29,220);
text("400 F",28, 245);
line(28,245,29,245);
text("375 F",28, 270);
line(28,270,29,270);
text("350 F",28, 295);
line(28,295,29,295);
text("325 F",28, 320);
line(28,320,29,320);
text("300 F",28, 345);
line(28,345,29,345);
text("275 F",28, 370);
line(28,370,29,370);
text("250 F",28, 395);
line(28,395,29,395);
text("225 F",28, 420);
line(28,420,29,420);
text("200 F",28, 445);
line(28,445,29,445);
text("175 F",28, 470);
line(28,470,29,470);
text("150 F",28, 495);
line(28,495,29,495);
text("125 F",28, 520);
line(28,520,29,520);
//write time values
textFont(font10);
textAlign(RIGHT);
text("0:00",45,540);
line(30,520,30,524);
line(55,520,55,522);
text("2:00",95,540);
line(80,520,80,524);
line(105,520,105,522);
text("4:00",145,540);
line(130,520,130,524);
line(155,520,155,522);
text("6:00",195,540);
line(180,520,180,524);
line(205,520,205,522);
text("8:00",245,540);
line(230,520,230,524);
line(255,520,255,522);
text("10:00",295,540);
line(280,520,280,524);
line(305,520,305,522);
text("12:00",345,540);
line(330,520,330,524);
line(355,520,355,522);
text("14:00",395,540);
line(380,520,380,524);
line(405,520,405,522);
text("16:00",445,540);
line(430,520,430,524);
line(455,520,455,522);
text("18:00",495,540);
line(480,520,480,524);
line(505,520,505,522);
text("20:00",545,540);
line(530,520,530,524);
//draw boxes for bean,env and stopwatch
stroke(0);
fill(255,255,255);
rect(325,55,80,40);
rect(425,55,80,40);
//write box titles
fill(0,0,0);
textFont(font12);
textAlign(CENTER);
text("Bean Temp",362,50);
text("Env Temp",462,50);
textFont(font18);
text("Elapsed Time",590,40);
//write the temp in C and F
fill(0,0,0);
textFont(font24);
textAlign(LEFT);
tempF = ((tempC*9)/5) + 32;
text(str(int(tempF)) + " F", 348, 85);
tempEnvF = ((tempB*9)/5) + 32;
text(str(int(tempEnvF)) + " F", 448,85);
}
drawbuttons();
if(mousePressed && rectSTART())
{
startSECOND=second();
startMINUTE = minute();
startTOTAL = startMINUTE*60 + startSECOND;
startcount = true;
}
if(mousePressed && rectSTOP())
{
startcount = false;
}
if(mousePressed && rectRESET())
{
dis_m = 0;
dis_s = 0;
}
calculate();
display();
}
void drawbuttons()
{
fill(6,203,27); rect(562,115,50,20); // green start
fill(250,0,17); rect(562,140,50,20); // red stop
fill(250,122,30); rect(562,165,50,20); //orange reset
fill(0);
textFont(font10);
textAlign(CENTER);
text("Start", 588,130);
text("Stop", 588, 155);
text("Reset", 588, 180);
}
boolean rectSTART()
{
if(mouseX >= 562 && mouseX <= 612 && mouseY >= 115 && mouseY <= 135) return true;
else return false;
}
boolean rectSTOP()
{
if(mouseX >= 562 && mouseX <= 612 && mouseY >= 140 && mouseY <= 160) return true;
else return false;
}
boolean rectRESET()
{
if(mouseX >= 562 && mouseX <= 612 && mouseY >= 165 && mouseY <= 185) return true;
else return false;
}
void calculate()
{
if(startcount)
{
stopMINUTE = minute();
stopSECOND = second();
stopTOTAL = stopMINUTE*60 + stopSECOND;
int diff = stopTOTAL-startTOTAL;
dis_m = diff/60;
dis_s = diff - dis_m*60;
}
}
void display()
{
stroke(0);
fill(255,255,255);
rect(538,50,100,60); // stopwatch
fill(0);
textFont(font24);
textAlign(LEFT);
text(nf(dis_m,2)+":"+nf(dis_s,2),555,88);
}