Once again i find my self hitting a brick wall....the problem I am having is that i have serial data coming in and i would like to be able add the data to an array (or arraylist) of variable length and then do stuff with that array. I am not entirely sure what the "proper" way of doing this is. I have seen some people use append and extend but for some reason they didnt quite work out for me and used up way to much memory too quickly. I have also played around with using an object and doing a .add for the serial data to come in but im not quite talented enough yet to figure it out and i think it might be more trouble than its worth. So at the end of the day how does one write to an array and array list and then expand that same array?
I have posted code below for reference
thanks so much for the help in the past and future
import controlP5.*;
ControlP5 controlP5;
DropdownList p1;
import processing.serial.*;
Serial myPort; // The serial port
PFont font; // Declare PFont variable
PrintWriter output; //printer
int count = 0;
boolean stop = false;
int intPres = 1013; // sea level hPa
int arraysize = 0;
ArrayList rxdata = new ArrayList();
public void setup () {
String out = "data/" + month() + "_" + day() + "_" + hour() + "_" + minute() + "_data.csv";
output = createWriter(out);
font = loadFont( "ArialMT-20.vlw" ); // Must also use [Tools -> Font Selector]
// set the window size:
size(475, 300);
controlP5 = new ControlP5(this);
controlP5.addButton("Start_Stop_Data",128,25,80,80,19);
controlP5.addButton("Save",128,25,100,80,19);
controlP5.addButton("Clear",255,25,120,80,19);
controlP5 = new ControlP5(this);
//dropdown list
p1 = controlP5.addDropdownList("myList-p1",350,25,100,120);
customize(p1);
//initialize a serial port with first available port which will be selectable later
myPort = new Serial(this, Serial.list()[0], 57600);
myPort.bufferUntil('\n');
void controlEvent(ControlEvent theEvent) {
// PulldownMenu is if type ControlGroup.
// A controlEvent will be triggered from within the ControlGroup.
// therefore you need to check the originator of the Event with
// if (theEvent.isGroup())
// to avoid an error message from controlP5.
if (theEvent.isGroup()) {
println(int(theEvent.group().value()));
myPort.stop();
myPort = new Serial(this, Serial.list()[int(theEvent.group().value())], 57600);
myPort.bufferUntil('\n');
redraw();
}
}
void Start_Stop_Data() {
if(stop == false)
{
stop = true;
println("Stop");
}
else
{
stop = false;
println("Start");
}
}
public void Save()
{
println("Save");
if( arraysize <= 0)
{
println("no data to save");
}
I am trying to get my program to exit a loop based on an event such as mouse event below; however, it doesn't seem to want to stop looping even with a delay. Any ideas how to get this loop to stop based on an event?
Thanks
void mousePressed() {
stop = true;
}
void draw() {
ArrayList rxdata = new ArrayList();
while (myPort.available() > 0) { //principal loop
String inBuffer = myPort.readStringUntil(',');
//data
if (inBuffer != null && stop ==false) {
rxdata.add(inBuffer);
// int size = rxdata.size(); // 2
println(rxdata.get(count)); // a
So here is the deal i have been wrestling around with this for quite some time and I have finally decided to ask for help.
What I am trying to do is create a program that graphs the serial data coming in (one axis for starters, three if i or someone feels compelled) and also can save all the information being gathered from the Arduino. I haven't been able to figure out how to write all the data coming in to a text file right now. The path I am trying is to save it all to an array and then magically save that array.
import controlP5.*;
ControlP5 controlP5;
DropdownList p1;
int comnum = 0;
import processing.serial.*;
Serial myPort; // The serial port
int xPos = 1; // horizontal position of the graph
int index = 0;
int[] xaxis;
int[] yaxis;
int[] zaxis;
int[] press;
public void setup () {
// set the window size:
size(400, 300);
controlP5 = new ControlP5(this);
controlP5.addButton("Start",100,25,100,80,19);
controlP5.addButton("Stop",255,25,120,80,19);
controlP5.addButton("Save",128,25,140,80,19);
controlP5.addButton("Clear",255,25,160,80,19);
controlP5 = new ControlP5(this);
//
p1 = controlP5.addDropdownList("myList-p1",25,50,100,120);
customize(p1);
//initialize a serial port with first available port which will be selectable later
myPort = new Serial(this, Serial.list()[0], 57600);
myPort.bufferUntil('\n');
void controlEvent(ControlEvent theEvent) {
// PulldownMenu is if type ControlGroup.
// A controlEvent will be triggered from within the ControlGroup.
// therefore you need to check the originator of the Event with
// if (theEvent.isGroup())
// to avoid an error message from controlP5.
if (theEvent.isGroup()) {
println(int(theEvent.group().value()));
myPort.stop();
myPort = new Serial(this, Serial.list()[int(theEvent.group().value())], 57600);
myPort.bufferUntil('\n');
redraw();
}
}
public void Stop() {
println("Stop");
}
public void Start() {
println("Start");
xPos = 0;
background(0);
}
void Save()
{
println("Save");
}
public void Clear() {
println("Clear");
xPos = 0;
background(0);
inStringy = trim(inStringy);
// convert to an int and map to the screen height:
float inByte = float(inStringy);
inByte = map(inByte, 0, 1023, 0, height);
//
// // draw the line:
stroke(127,34,255);
line(xPos, height, xPos, height - inByte);
//
// // at the edge of the screen, go back to the beginning:
if (xPos >= width) {
xPos = 0;
background(0);
}
else {
// // increment the horizontal position:
xPos++;
}
}