Paso 3: Procesamiento
Vamos a utilizar un esquema de procesamiento para salvar los datos en serie de nuestro Arduino y guardarla en nuestro ordenador.
Si tienes problemas entendiendo como proceso funciona le deben comprobar este gran tutorial.
import processing.serial.*; Serial myPort; String dataReading = ""; String [] timeFile = {}; String [] distanceFile = {};void setup() {size(500,500);// Open the port you are using ([1] in my case) at the rate you want. You can use println(Serial.list())to print the list your Serial ports.myPort = new Serial(this, Serial.list()[1], 9600);myPort.bufferUntil('\n');}void draw() { } void serialEvent(Serial myPort) { dataReading = myPort.readString();// Here we are creating good looking timestamp :) String timestamp = nf(day(),2) + "." + nf(month(),2) + "." + year() + "-" + nf(hour(),2) + ":" + nf(minute(),2) + ":" + nf(second(),2); int distance = parseInt(dataReading.trim()); // The trim function removes all whitespaces (it craches otherwise) if(distance < 100){ String bla = timestamp + " Distance is " + distance + " cm"; println(bla); timeFile = append(timeFile, bla); saveStrings("timestamp/timestamp.txt", timeFile); } }