We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Sorry for the trivial question, I'm a novice girl ... I would like to save as a name and be able to load an array list to compile a graph (y-axis data from the array list and x-axis value to each mouse pressed) exists a way? Thanks so much
ArrayList points = new ArrayList(); void setup() { size(900, 800); for (int i = 0; i < 13; i++) { points.add(new PVector(i, 20 + 10noise(i0.1))); }//for background(190); }// void draw() { background(190); // show data int y=50; for (PVector pv : points) { // show data text(pv.x, 100, y); text(pv.y, 200, y); y+=20; //next line // middle line line( 190, 30, 190, 440); }//for }//
Answers
Your code a little better formatted:
sorry ..... I'm a beginner in this splendid world of processing ...
I'm trying to learn but I'm finding it difficult ........
in this version, the graph is shown in red as line graph
what do you mean by this:
thank you for your interest.... my intention is to be able to represent a table of values and to represent it with line graph (axis y values received from arduino and axis x = 0 with each pressed mause advance one), save them with name and be able to recall, represent and compare them with another table and chart ....
I find it a very complicated sketch, it would calm me to understand how to save with name and load the table -.....
I don't know about Arduino but here you can
At the beginning and when pressing New some points are added, this is not necessary. Search necessary in the code to change this.
A typical stored data file looks like this (comma separated float values)
Chrisir ;-)
fantastic ..... I have not only figured out how to operate the save buttons with name and charge ....
I would like to save them on a file that can be loaded when I need it .....
??
When you make a graph with the mouse you can save it.
You can enter any name in the dialogue by typing the name
When you click the Load button you can load the file again
but the only key I see reproduce and new .... others I do not see ....
I would not want the mouse to create a value for me, but with each pressed only the progress of the table in the value x (0 to 1 to 2 to 3 ....)
there are 3 buttons
what is the height of your display?
are you on a small laptop?
do you see the lower area of the canvas?
ok thanks for your help .... I resized the sketch to fit my screen ....... now I study your example and I try to write the sketch and transcribe it all on a graph through the graphic library .... thanks again ....
Thanks so much! your example has taught me a lot. Much more than what they teach here in Italy at school. But I can not understand how to use the function load and new how to recall the new points on the chart without deleting those already represented on the chart and make a table appear side by side (without deleting the one just completed) ....
You are welcome.
First, when we hit new, the old list gets deleted and some values are just entered. You might want to change this in the lines 174 to 178
Similarly when loading the list gets deleted in line 293
When you delete this line the loaded points are added to the list (instead of clearing the list first).
That’s a first step but no real comparison of two data set (do you want two or even more than 2?)
Two tables
To achieve this you would have to work with a 2nd ArrayList (line 9) and change the display x position of the 2nd table (and graph color).
Also for loading and saving you either have 2x3 buttons so both tables have their own 3 buttons (new,load,save) or you have 3 buttons and kick out one table when loading the next. If 2 tables are there, copy table 2 into table 1 and load the new table into table 2. so the new table does not replace the previous table (2) but the one before (1).
This requires a little bit of thinking and work. I am on a journey and writing on my phone, so I can’t do anything for you.
Chrisir
Thank you. Interesting, challenging ..... you're right, what I'd like to accomplish are actually two ArrayList with the relative color (different) of the line represented on the chart and listed next to the first Array List without replacing it (only the valory of the y axis because the values of the x axis would start again from 0 ...)
what do you think about it? I still do not understand how to draw the graph (y axis values read via Arduino and x axis scales from 0 to 13 where each mouse pressed advances by 1) and relative table. And the part that I think very complicated to achieve, recall a previously saved Array List and be able to superimpose it on the chart (line of another color) and add it to the table just created .........
When the y value comes from arduino and x by mousePressed do you mean by a mouse click anywhere on the screen the x is just increased by 1 or is the x where you click the mouse?
Also are the y values averaged from your last mouse click onwards...?
Two ArrayLists
To the double load of ArrayList; i told you how to do it.
When you duplicate line 9 and change the name you got 2 different arrayLists
Now you have an indicator that tells you what ArrayList is the active one (eg
activeArrayListIsLeft==true
) and then on loading fill the data only in the active ArrayListDuplicate the lines for displaying the ArrayList too
Thank you for your lessons .... You want a mouse click anywhere on the screen the x is increased by 1 ..... I have to study better and more the sketch .... thanks again Chrisir .....
looks great!
Cool controls, Sir.
remarks:
the button reads Salve, should be
Save
(or is it Italian?)I display a red help text "
Use buttons below
" - not correct anymore, because new/load/save are on top nowwhen mouse is clicked on controls it should not set a new point on the graph...
new version with 2 tables and graphs.
Delete key and Backspace key are now referring to the different tables separately
Use key 1 and 2 to set the active table
New, Load and Save are referring to the active table.
Hit x to hide / show help text
Chrisir ;-)
Thanks Chrisir I have to congratulate you and if you ever pass from Italy I offer a beer ..... I'm learning so much from you ..... I fail to understand how to make and map the values in a graph x and y (giving the due proptions in y values read by arduino and x numbers from o to 13)
Hm.
Not sure what you mean.
I don't know about your values.
Use
println()
to find out how many values you get and which size they are (between 0 and 1000 or between 300 and 400? huge difference).You could make a timer and read in values every 1/3 second automatically and even take the average of the values.
You could start this when you click the mouse ONCE then it runs automatically 13 times every 1/3 second or so (look at millis() in reference and google timer for it).
Now, when your values are between 0 and 0.5 they are very small. Use map() to enlarge them. See reference.
Now, in math y = 0 value is at the bottom (or in the middle) of a coordinate system. In processing it's at the top. Bad. So maybe you want
resultY = 300 - yFromArduino;
- with that you would flip it upside down.I did not explain well ... the graph that I mean and as an example that I enclose, the value of the y axis are read by arduino and in the x axis the value is given by the mouse pressed which increases the value of 1 each time
and your question is....?
Sorry if I'm not precise ... my question is: is it possible to represent the line (y = values from Arduino and x = mouse pressed increases by one) in the chart I posted?
yes; in function serialEvent you read a value
add that to the active arraylist on mousepressed
see lines 505 to 510
So store value in serialEvent (while loop??)
And then move it with ...add into the ArrayList
Solved..?
thanks for the interest, I'm still studying the sketch but I have not yet managed to draw the chart ....
This is what I have in mind, but I have not succeeded yet .... Point1 and Point2 I would like to draw in the GPlot chart .... import processing.serial.*; import controlP5.*;
import grafica.*;
}
ermina is very advanced with this library
see
https://forum.processing.org/two/discussion/26003/how-can-i-numerate-x-axis-in-a-graph#latest
and her other discussions...
thank you .... check and study ....
advice: Is it better to use the map () function to construct and draw lines in a graph?
not enough context
try it
Sorry but I can not understand, if you want the line that is played (576 of the sketch) can you play in another position on the screen and change the scale?
Yes you can.
Do you want to use the library grafica?
Then see the link to erminas discussion please.
Of course you need two objects GPlot and set the position and size (setDim()!!!) separately
Then you need to for loop over points and copy them into GPlot
You can use map() here but GPlot is doing a lot of adjustments for you I think
Chrisir
You could even without using the grafica library? I would like the simple sketch and in a second time use the grafica library....
yes, can also do that without grafica library
For example these lines
y values are already scaled with * 10
you can use map() as well:
float yvalue = map( pv.y, 0, 40, 0, height);
and then use yvalue in line(10 + pv.x*30, yvalue, .......);
and also where prev.x and prev.y are set
Use in map the values that are needed. 0..40 is the range of the incoming data, 0 to height is the resulting range. When you receive values between 0 and 20 replace 40 with 20.
here
very small graphs
Thanks for your patience in teaching me ... Now I'm implementing the graph, but now I was wondering if it was possible to create and manage at least 4 Array List ... I managed to show 3 to the monitor but not to manage them .. .
Sure possible, although always easier not to change such plans in the first place.
Change this line to int : boolean activeArrayListIsLeft = true;
So it tells which graph is active currently
italianoThank you, honestly, what I would like to achieve and 4 Array List with its title and graphic representation where the first can be edited in real time and the other three derived from saved files
Sure possible
Lots of changes here :
4 columns now
you can click mouse above each column to activate it (or use 0,1,2,3)
Backspace works on active list
separate Help Screen with new button "Help"
toggle display of Help box with "x"
toggle display of entire table with data and texts with "m" or Escape
Chrisir ;-)