Sei sulla pagina 1di 5

import processing.serial.

*;
import ddf.minim.* ; //Librer�a para m�sica
//m�sica de alerta
Minim AudioManager;
AudioPlayer MySong;

Serial myPort;

float hMercurio;
int termometroY1 = 160;
int termometroY2 = 550;
int wBase = 100;

PFont font;
boolean Celsius;
float p=0;
float s=0;

String ritmo="";
int xPos = 50; // horizontal position of the graph
float height_old = 100;
float height_new = 0;
float inByte = 0;

//bandera que nos indicar� el momento para poder reproducir una m�sica de alerta
si se ha alcanzado un limite de temperatura
boolean musica = false;
boolean ritmoBandera = false;

void setup(){
myPort = new Serial(this, Serial.list()[0], 9600);
myPort.bufferUntil('\n');
size(1400,700);
PImage sensorMedico;
sensorMedico=loadImage("fondo.png");
image(sensorMedico,1000,0,380,700);
PImage sensorMedico2;
sensorMedico2=loadImage("fondo2.png");
image(sensorMedico2,600,0,400,700);
PImage sensorMedico3;
sensorMedico3=loadImage("fondo3.png");
image(sensorMedico3,0,0,600,150);
PImage sensorMedico4;
sensorMedico4=loadImage("fondo3.png");
image(sensorMedico4,0,150,49,550);
PImage sensorMedico5;
sensorMedico5=loadImage("electrocardiograma.png");
image(sensorMedico5,49,150,551,400);
PImage sensorMedico6;
sensorMedico6=loadImage("fondo3.png");
image(sensorMedico6,49,550,551,150);
smooth();
// variables
hMercurio = 22.20;
// tipograf�a.
font = loadFont("Calibri-Bold-48.vlw");
}

void draw(){
Fondos();
titulo();
termometroBase();
mercurio();
textoGrados();
dibujaLasMarcas();
serialEvent(myPort);
inteligenciaAritificial();
}
void titulo(){
text("Temperatura",800,70);
text("Ritmo Cardiaco",340,70);
}
void textoGrados(){
fill(64);
textAlign(CENTER,CENTER);
textFont(font, 48);
float grados = YtoGrados(hMercurio);
String gradosTexto = nf(grados,0,1)+"�";
text(gradosTexto, width-630, termometroY2-hMercurio);
// grados fahrenheit
float F = gradosCTOgradosF(grados);
String FTesto = nf(F,0,1)+"�";
// uno dei due testi
if(Celsius){
text(gradosTexto, (width/7)+10, termometroY2-hMercurio);
} else {
text(FTesto, (width/7)*5+10, termometroY2-hMercurio);
}
}

float YtoGrados(float Y){


float grados = map(Y,0,termometroY2-termometroY1,-25,50);
return(grados);
}

void termometroBase(){
// gris claro
fill(192);
stroke(192);
// formas geom�trica
ellipse((width/2)+150,termometroY1,wBase,wBase);
ellipse((width/2)+150,termometroY2,wBase,wBase);
rect((width/2)+150-wBase/2,termometroY1,wBase,termometroY2-termometroY1);
}
void mercurio(){
// escala
fill(220);
stroke(255);
rect((width/2)+150-10,termometroY1,20,termometroY2-termometroY1);
// mercurio
fill(#CC0000);
stroke(#CC0000);
ellipse((width/2)+150,termometroY2,30,30);
//
rect((width/2)+150-5,termometroY2-hMercurio,10,hMercurio);

}
float gradosToY(float grados){
float Y = map(grados,-25,50,0,termometroY2-termometroY1);
return(Y);
}
void dibujaLasMarcas(){
int intervalo = 5;
stroke(64);
// grados Celsius
for(float t = -25; t<=50; t+=intervalo ){
float Y = termometroY2 - gradosToY(t);
if(t % 10 == 0){
line(width/2 - 20+150, Y, width/2 - 30+150, Y);
} else {
line(width/2 - 20+150, Y, width/2 - 25+150, Y);
}
}
// fahrenheit aprox -10 > 120
for(float t = -10; t<=120; t+=intervalo ){
float inGrados = gradosFTOgradosC(t);
float Y = termometroY2 - gradosToY(inGrados);
if(t % 10 == 0){
line(width/2 + 170, Y, width/2 + 180, Y);
} else {
line(width/2 + 170, Y, width/2 + 175, Y);
}
}

float gradosCTOgradosF(float grados){


float F = (grados*1.8)+32;
return(F);

}
float gradosFTOgradosC(float F){
float grados = (F-32) / 1.800;
return(grados);
}
void serialEvent(Serial myPort){
if(myPort.available()>0){
String inString= myPort.readString();
if(inString!=null){
int pos=inString.indexOf(',');
if(pos!=-1){
ritmo=inString.substring(0,pos);
if (ritmo != null) {
// trim off any whitespace:
ritmo = trim(ritmo);
// If leads off detection is true notify with blue line
if (ritmo.equals("!")) {
stroke(0, 0, 0xff); //Set stroke to blue ( R, G, B)
inByte = 512; // middle of the ADC range (Flat Line)
}
// If the data is good let it through
else {
stroke(0xff, 0, 0); //Set stroke to red ( R, G, B)
inByte = float(ritmo);
}
System.out.println(ritmo);
if(Integer.parseInt(ritmo) >= 200){
ritmoBandera = true;
}
else{
ritmoBandera = false;
}
//Map and draw the line for new data point
inByte = map(inByte, 0, 1023, 0, 600);
height_new = 650- inByte;
line(xPos - 1, height_old, xPos, height_new);
height_old = height_new;
// at the edge of the screen, go back to the beginning:
if (xPos >= 598) {
xPos = 50;
PImage sensorMedico5;
sensorMedico5=loadImage("electrocardiograma.png");
image(sensorMedico5,49,150,551,400);
}
else {
// increment the horizontal position:
xPos++;
}
}
String inString2=inString.substring(pos+1);
String temperatura=inString2;
float aux=float(temperatura)+110.20;
hMercurio = aux;
// limites
if(hMercurio > (termometroY2-termometroY1)){
hMercurio = termometroY2-termometroY1;
}
if(hMercurio < 0){
hMercurio = 0;
}
if(hMercurio>=50.0){
musica = true;
}
else{
musica = false;
}

}
}
}
}

void Fondos(){
PImage sensorMedico;
sensorMedico=loadImage("fondo.png");
image(sensorMedico,1000,0,380,700);
PImage sensorMedico2;
sensorMedico2=loadImage("fondo2.png");
image(sensorMedico2,600,0,400,700);
PImage sensorMedico3;
sensorMedico3=loadImage("fondo3.png");
image(sensorMedico3,0,0,600,150);
PImage sensorMedico4;
sensorMedico4=loadImage("fondo3.png");
image(sensorMedico4,0,150,49,550);
PImage sensorMedico6;
sensorMedico6=loadImage("fondo3.png");
image(sensorMedico6,49,550,551,150);
}

//M�todo que se encargar� de reaccionar dependiendo de las respuestas del medio


en que se encuentra
void inteligenciaAritificial(){
if(musica==true || ritmoBandera==true){
MySong.play();
}
else{
MySong.pause();
MySong.rewind();
}
}

//M�todo predeterminado que responder� a las teclas que presionemos en nuestro


teclado
void keyPressed(){
//Al momento de presionar la tecla Esc, nos permitir� salir de la simulaci�n
evitando cualquier mal momento o salvando la via de nuestro sujeto de prueba.
if(key==ESC){
key = 0;
exit();
}
}

Potrebbero piacerti anche