import processing.serial.*;
PFont font;
int an1;
int val = 0;
int xPos=0;
String buff = "";
int displaySize = 2;
int a=127;
Serial port;
void setup(){
size(600,500);
smooth();
port = new Serial(this, Serial.list()[0], 9600);
port.write(65);
font = loadFont("ArialMT-24.vlw");
textFont(font, 24);
}
void draw(){
while (port.available() > 0) {
serialEvent(port.read());
}
}
void serialEvent(int serial) {
if(serial != '\n') {
buff += char(serial);
}
else {
int curX = buff.indexOf("Alcohol:");
if(curX >=0){
String val = buff.substring(curX+8);
an1 = Integer.parseInt(val.trim());
println(an1);
xPos++;
if(xPos > width) xPos = 0;
fill(50,5);
noStroke();
rect(0,0,width,height);
fill(0);
rect(xPos+displaySize+1, 0, 160, height);
fill(255, an1-20);
text(buff, xPos+10, an1-10);
sensorTic(xPos,an1+20);
}
buff = "";
}
}
void sensorTic(int x, int y){
fill(255, 360-an1,0,an1-35);
ellipse(x,y,displaySize+an1/20,displaySize+an1/20);
}