Sei sulla pagina 1di 4

Codigo de arduino:

void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
}

int valpwm;
float valtemp;

// the loop routine runs over and over again forever:


void loop() {
int sensorValue = analogRead(A1);

valtemp = (sensorValue*2500.00)/1023.00;
delay(1);
Serial.println(valtemp);
delay(1000);

Codigo de Processing

import processing.serial.*;

Serial myPort; // The serial port


int xPos = 1; // horizontal position of the graph

//Variables to draw a continuous line.


int lastxPos=1;
int lastheight=0;

boolean nuevoDato = false;

Float dato = 0.0;


Float ultimoDato = 0.0;

Float umbral = 100.0; // Umbral para que cambies.

PrintWriter log;

void setup () {

// set the window size:


size(1800, 400);
log = createWriter("log.csv"); //Logger

// List all the available serial ports

// Check the listed serial ports in your machine


// and use the correct index number in Serial.list()[].

myPort = new Serial(this, "COM5", 9600); // Aca poner la COM de tu arduino

// A serialEvent() is generated when a newline character is received :


myPort.bufferUntil('\n');
background(0); // set inital background:
}
void draw () {

if (nuevoDato)
{

nuevoDato = false;
stroke(127,34,255); //stroke color
strokeWeight(1); //stroke wider
line(lastxPos, lastheight, xPos, height - dato);
lastxPos= xPos;
lastheight= int(height-dato);

// at the edge of the window, go back to the beginning:


if (xPos >= width) {
xPos = 0;
lastxPos= 0;
background(0); //Clear the screen.
}
else {
// increment the horizontal position:
xPos++;
}
}
}

void serialEvent (Serial myPort) {

String inString = myPort.readStringUntil('\n');


//System.out.println(inString);
if (inString != null) {
inString = trim(inString); // trim off whitespaces.
dato = float(inString); // convert to a number.

//log.println(millis()+","+dato);
log.println(hour()+":"+minute()+":"+second() +" , "+dato);

if (dato > (ultimoDato + umbral) || dato < (ultimoDato - umbral))


{
dato = map(dato, 0, 1023, 0, height); //map to the screen height.
ultimoDato = dato;
nuevoDato = true;

}
}

void exit() {

log.flush(); // Writes the remaining data to the file


log.close(); // Finishes the file

println("CErrado");
super.exit();
}

Conexión de arduino

Potrebbero piacerti anche