I've been searching around trying to figure out how to do this but alas I can't figure it out :( I am trying to send data from Arduino to processing and have processing spit out a text file that I will then have Arduino read. I have 8 RGB LEDS with 3 shift registers, a DHT Temp Sensor, a photoresistor, and an electret microphone. The input from the 3 senors are controlling the color of the RGB LEDS. My code on the Arduino side works but I can't get processing to read the data and save it to a text file. Here is my code so far (it's probably all wrong, I'm new to programming)
- import processing.serial.*;
Serial myPort;
PrintWriter output;
int r;
int g;
int b;
void setup() {
output = createWriter("data/data.txt");
myPort = new Serial(this, "/dev/tty.usbmodemfa121", 9600);
myPort.bufferUntil('\n');
}
void serialEvent(Serial myPort){
String myString = myPort.readStringUntil('\n');
int data [] = int(split(myString, ','));
if (data.length > 1) {
r = data[0];
g = data[1];
b = data[2];
println("Printing RGB Vals to File");
output.println(r+","+g+","+b);
output.flush();
}
}
void stop(){
output.close();
super.stop();
}
1