We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I have several sensors on my arduino that I would like to log
Data comes from the Arduino in the form of a string and is formatted in the following manner (there are 6 fields)
"10.2", "123.33", "0.00", "1023.00", "99.01", "256.9"/r
in processing I am reading the string then splitting and converting it in to a float and that seems to be working fine.
What I need to do is store the information in an array so I can output the information however I also need to be able to shift the last readings in and out as I would like to keep track of the last 60 values for each sensor.
for example
{0}, {0, 1, 2, 3, -> whatever the incoming values are etc-> 58, 59, 60};
When a new value comes in the new values is added and shifted to the left.
{0}, {1, 2, 3, 4, -> whatever the incoming values are etc-> 59, 60, 61};
Ideally i would like to do this without using loops as some of the other functions are kind of time critical.
I hope that made sense and thanks in advance for any assistance or ideas on this.
Answers
Thanks @TfGuy44 will try that out. looks a lot less complex than the way I was trying to do it.
Not sure if i'm holding my tongue on the right angle for this one..
Seems that no matter what I add in to lastSixty the length is allays 1.
`class DataSet { float[] data = new float[6]; DataSet(float a, float b, float c, float d, float e, float f ){ data[0] = a; data[1] = b; data[2] = c; data[3] = d; data[4] = e; data[5] = f; } } ArrayList lastSixty;
void setup() { size(640, 360); lastSixty = new ArrayList();
// Add new data to end: lastSixty.add(new DataSet(1, 2, 3, 4, 5, 6)); }
void draw() {
//ArrayList lastSixty = new ArrayList(); // Remove oldest data: //lastSixty.remove(0);
// Maintain sixty data: //while( lastSixty.size() > 60 ){ lastSixty.remove(0); }
println(lastSixty.size()); // println(lastSixty.get(2));
// Access the 5th most recent record's third data: //println( lastSixty.get(lastSixty.size() - 5 ).data[2] ); }`
Doh... Scratch that... I just realised I was looking at the array the wrong way around... Typical..!! guess that's what you get from being on the bottom side of the planet :)
Australia?
@Chrisir Close, but a little Further down :P New Zealand :)
;-)
You make your life easier when you tell the ArrayList its class.
Greetings to New Zealand
Chrisir ;-)
this is with
noLoop()
... you want to comment that out laterThanks @Chrisir, Yes using a dataset really did make it so much easier :) where are you from?
That's this line:
(just to make sure we are on the same page ;-) )
I am from Germany
:) We are in the same memory space. Thanks
@Chrisir is there a way to get the size of data[] to see how many sensors are in there? kind of like a println(data.size())?
data.length
More in the reference: https://processing.org/reference/Array.html
Kf