Salve,
come da titolo ho un piccolo problema con processing.
il mio progetto, essenzialmente, è un ascensore dal quale dovrei leggere, cosa che già riesco ad eseguire tramite il comando serialprint, i dati come velocità e corrente che attraversa il motore per poi trascriverli in un file .txt.
Per quanto riguarda la velocità sono già in grado di eseguire ciò, il problema si verifica quando devo salvare i dati della corrente, infatti mentre la velocità è un int la corrente è un float.
Il salvataggio della corrente può anche essere eseguita in un altro file.
Di seguito lo script di processing:
import processing.serial.*;
Serial port;
PrintWriter output;
int rpmAv;
void setup() {
// Create a new file in the sketch directory
output = createWriter("rpmAv.txt");
// GO FIND THE ARDUINO
println(Serial.list()); // print a list of available serial ports
// choose the number between the [] that is connected to the Arduino
port = new Serial(this, Serial.list()[0], 9600); // make sure Arduino is talking serial at this baud rate
port.bufferUntil('\n'); // set buffer full flag on receipt of carriage return
}
void serialEvent(Serial port){
String inData = port.readStringUntil('\n');
inData = trim(inData); // cut off white space (carriage return)
rpmAv = int(inData); // convert the string to usable int
}
void draw() { // Could use void loop() here instead?
output.println(rpmAv); // Write the BPM to the file
}
void keyPressed() {
output.flush(); // Writes the remaining data to the file
output.close(); // Finishes the file
exit(); // Stops the program
}
grazie in anticipo.