Skip to content

Commit b12b0e1

Browse files
committed
Moved getting the double address to the library side. User just passes the variable now. Added actually example and image corresponding to quickstart
1 parent 1ede2b6 commit b12b0e1

File tree

10 files changed

+148
-72
lines changed

10 files changed

+148
-72
lines changed

Plotter/Plotter.cpp

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
1616
-------------------------------------------------------------------------------------------
1717
Plotter
18-
v1.0.0
18+
v1.1.0
1919
https://github.com/devinconley/ArduinoPlotter
2020
by Devin Conley
2121
===========================================================================================
@@ -44,55 +44,55 @@ Plotter::~Plotter() {
4444
delete temp;
4545
}
4646

47-
void Plotter::addTimeGraph(String title, int points_displayed, String labelA, double* refA) {
47+
void Plotter::addTimeGraph(String title, int points_displayed, String labelA, double & refA) {
4848
String labels[] = {labelA};
49-
double* refs[] = {refA};
49+
double* refs[] = {&refA};
5050
addGraphHelper(title, labels, refs, 1, false, points_displayed);
5151
}
5252

53-
void Plotter::addTimeGraph(String title, int points_displayed, String labelA, double* refA,
54-
String labelB, double* refB) {
53+
void Plotter::addTimeGraph(String title, int points_displayed, String labelA, double & refA,
54+
String labelB, double & refB) {
5555
String labels[] = {labelA, labelB};
56-
double* refs[] = {refA, refB};
56+
double* refs[] = {&refA, &refB};
5757
addGraphHelper(title, labels, refs, 2, false, points_displayed);
5858
}
5959

60-
void Plotter::addTimeGraph(String title, int points_displayed, String labelA, double* refA,
61-
String labelB, double* refB, String labelC, double* refC) {
60+
void Plotter::addTimeGraph(String title, int points_displayed, String labelA, double & refA,
61+
String labelB, double & refB, String labelC, double & refC) {
6262
String labels[] = {labelA, labelB, labelC};
63-
double* refs[] = {refA, refB, refC};
63+
double* refs[] = {&refA, &refB, &refC};
6464
addGraphHelper(title, labels, refs, 3, false, points_displayed);
6565
}
6666

67-
void Plotter::addTimeGraph(String title, int points_displayed, String labelA, double* refA,
68-
String labelB, double* refB, String labelC, double* refC,
69-
String labelD, double* refD) {
67+
void Plotter::addTimeGraph(String title, int points_displayed, String labelA, double & refA,
68+
String labelB, double & refB, String labelC, double & refC,
69+
String labelD, double & refD) {
7070
String labels[] = {labelA, labelB, labelC, labelD};
71-
double* refs[] = {refA, refB, refC, refD};
71+
double* refs[] = {&refA, &refB, &refC, &refD};
7272
addGraphHelper(title, labels, refs, 4, false, points_displayed);
7373
}
7474

75-
void Plotter::addTimeGraph(String title, int points_displayed, String labelA, double* refA,
76-
String labelB, double* refB, String labelC, double* refC,
77-
String labelD, double* refD, String labelE, double* refE) {
75+
void Plotter::addTimeGraph(String title, int points_displayed, String labelA, double & refA,
76+
String labelB, double & refB, String labelC, double & refC,
77+
String labelD, double & refD, String labelE, double & refE) {
7878
String labels[] = {labelA, labelB, labelC, labelD, labelE};
79-
double* refs[] = {refA, refB, refC, refD, refE};
79+
double* refs[] = {&refA, &refB, &refC, &refD, &refE};
8080
addGraphHelper(title, labels, refs, 5, false, points_displayed);
8181
}
8282

83-
void Plotter::addTimeGraph(String title, int points_displayed, String labelA, double* refA,
84-
String labelB, double* refB, String labelC, double* refC,
85-
String labelD, double* refD, String labelE, double* refE,
86-
String labelF, double* refF) {
83+
void Plotter::addTimeGraph(String title, int points_displayed, String labelA, double & refA,
84+
String labelB, double & refB, String labelC, double & refC,
85+
String labelD, double & refD, String labelE, double & refE,
86+
String labelF, double & refF) {
8787
String labels[] = {labelA, labelB, labelC, labelD, labelE, labelF};
88-
double* refs[] = {refA, refB, refC, refD, refE, refF};
88+
double* refs[] = {&refA, &refB, &refC, &refD, &refE, &refF};
8989
addGraphHelper(title, labels, refs, 6, false, points_displayed);
9090
}
9191

92-
void Plotter::addXYGraph(String title, int points_displayed, String labelX, double* refX,
93-
String labelY, double* refY) {
92+
void Plotter::addXYGraph(String title, int points_displayed, String labelX, double & refX,
93+
String labelY, double & refY) {
9494
String labels[] = {labelX, labelY};
95-
double* refs[] = {refX, refY};
95+
double* refs[] = {&refX, &refY};
9696
addGraphHelper(title, labels, refs, 2, true, points_displayed);
9797
}
9898

@@ -172,6 +172,6 @@ void Plotter::GraphNode::plot() {
172172
Serial.print(size); Serial.print(INNER_KEY);
173173
for (int i = 0; i < size; i++) {
174174
Serial.print(labels[i]); Serial.print(INNER_KEY);
175-
Serial.print(*refs[i]); Serial.print(INNER_KEY);
175+
Serial.print(*(refs[i])); Serial.print(INNER_KEY);
176176
}
177177
}

Plotter/Plotter.h

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
1616
-------------------------------------------------------------------------------------------
1717
Plotter
18-
v1.0.0
18+
v1.1.0
1919
https://github.com/devinconley/ArduinoPlotter
2020
by Devin Conley
2121
===========================================================================================
@@ -38,11 +38,11 @@ class Plotter {
3838
- title: String with title of graph
3939
- points_displayed: number of points to be shown at a given time. Used to control time-scaling
4040
- labelA: String with label of the plotted variable
41-
- refA: reference to global double variable that will be updated throughout program (ie. &global_double)
41+
- refA: reference to global double variable that will be updated throughout program
4242
4343
Similar methods for multi-variable graphing vs. time are declared below and follow the same format
4444
*/
45-
void addTimeGraph(String title, int points_displayed, String labelA, double* refA);
45+
void addTimeGraph(String title, int points_displayed, String labelA, double & refA);
4646

4747
/*
4848
Add an X vs. Y graph
@@ -51,12 +51,12 @@ class Plotter {
5151
- title: String with title of graph
5252
- points_displayed: number of points to be shown at a given time. Determines duration of data persistance
5353
- labelX: String with label of variable to be plotted along X-axis
54-
- refX: reference to global double X-variable that will be updated throughout program (ie. &global_double)
54+
- refX: reference to global double X-variable that will be updated throughout program
5555
- labelY: String with label of variable to be plotted along Y-axis
56-
- refY: reference to global double Y-variable that will be updated throughout program (ie. &global_double)
56+
- refY: reference to global double Y-variable that will be updated throughout program
5757
*/
5858
void addXYGraph(String title, int points_displayed,
59-
String labelX, double* refX, String labelY, double* refY);
59+
String labelX, double & refX, String labelY, double & refY);
6060

6161
/*
6262
Plot data
@@ -79,26 +79,27 @@ class Plotter {
7979
*/
8080
bool remove(int index);
8181

82+
8283
// Add a 2-variable graph vs. time
83-
void addTimeGraph(String title, int points_displayed, String labelA, double* refA,
84-
String labelB, double* refB);
84+
void addTimeGraph(String title, int points_displayed, String labelA, double & refA,
85+
String labelB, double & refB);
8586
// Add a 3-variable graph vs. time
86-
void addTimeGraph(String title, int points_displayed, String labelA, double* refA,
87-
String labelB, double* refB, String labelC, double* refC);
87+
void addTimeGraph(String title, int points_displayed, String labelA, double & refA,
88+
String labelB, double & refB, String labelC, double & refC);
8889

8990
// Add a 4-variable graph vs. time
90-
void addTimeGraph(String title, int points_displayed, String labelA, double* refA,
91-
String labelB, double* refB, String labelC, double* refC,
92-
String labelD, double* refD);
91+
void addTimeGraph(String title, int points_displayed, String labelA, double & refA,
92+
String labelB, double & refB, String labelC, double & refC,
93+
String labelD, double & refD);
9394
// Add a 5-variable graph vs. time
94-
void addTimeGraph(String title, int points_displayed, String labelA, double* refA,
95-
String labelB, double* refB, String labelC, double* refC,
96-
String labelD, double* refD, String labelE, double* refE);
95+
void addTimeGraph(String title, int points_displayed, String labelA, double & refA,
96+
String labelB, double & refB, String labelC, double & refC,
97+
String labelD, double & refD, String labelE, double & refE);
9798
// Add a 6-variable graph vs. time
98-
void addTimeGraph(String title, int points_displayed, String labelA, double* refA,
99-
String labelB, double* refB, String labelC, double* refC,
100-
String labelD, double* refD, String labelE, double* refE,
101-
String labelF, double* refF);
99+
void addTimeGraph(String title, int points_displayed, String labelA, double & refA,
100+
String labelB, double & refB, String labelC, double & refC,
101+
String labelD, double & refD, String labelE, double & refE,
102+
String labelF, double & refF);
102103

103104
// Destructor for Plotter class
104105
~Plotter();
@@ -119,7 +120,7 @@ class Plotter {
119120
String* labels;
120121
double** refs;
121122
};
122-
123+
private:
123124
// Private members
124125
int num_graphs;
125126
int total_size;

Plotter/examples/control_points_displayed/control_points_displayed.ino

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
Example to demonstrate effect of "Points Displayed" in Time Graph and in XY Graph
44
-------------------------------------------------------------------------------------------
55
Plotter
6-
v1.0.0
6+
v1.1.0
77
https://github.com/devinconley/ArduinoPlotter
88
by Devin Conley
99
===========================================================================================
10-
*/
10+
*/
1111

1212
#include "Plotter.h"
1313

@@ -23,12 +23,12 @@ void setup() {
2323
p = Plotter();
2424

2525
// Add X-Y graphs
26-
p.addXYGraph("X-Y graph w/ 500 points", 500, "x axis", &x, "y axis", &y);
27-
p.addXYGraph("X-Y graph w/ 200 points", 200, "x axis", &x, "y axis", &y);
26+
p.addXYGraph("X-Y graph w/ 500 points", 500, "x axis", x, "y axis", y);
27+
p.addXYGraph("X-Y graph w/ 200 points", 200, "x axis", x, "y axis", y);
2828

2929
// Add time graphs. Notice the effect of points displayed on the time scale
30-
p.addTimeGraph("Time graph w/ 500 points", 500, "x label", &x);
31-
p.addTimeGraph("Time graph w/ 200 points", 200, "x label", &x);
30+
p.addTimeGraph("Time graph w/ 500 points", 500, "x label", x);
31+
p.addTimeGraph("Time graph w/ 200 points", 200, "x label", x);
3232

3333
}
3434

Plotter/examples/dynamically_modify_graph_layout/dynamically_modify_graph_layout.ino

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
Example to demonstrate dynamic addition and removal of graphs
44
-------------------------------------------------------------------------------------------
55
Plotter
6-
v1.0.0
6+
v1.1.0
77
https://github.com/devinconley/ArduinoPlotter
88
by Devin Conley
99
===========================================================================================
10-
*/
10+
*/
1111

1212
#include "Plotter.h"
1313

@@ -29,20 +29,20 @@ void setup() {
2929
p = Plotter();
3030

3131
// Add a graph during setup
32-
p.addTimeGraph("x and y against time", 1000, "x label", &x, "y label", &y);
32+
p.addTimeGraph("x and y against time", 1000, "x label", x, "y label", y);
3333
}
3434

3535
void loop() {
3636

3737
// After 3 seconds add a 1-variable graph
3838
if (millis() > 3000 && add_first) {
39-
p.addTimeGraph("First dynamic addition", 1000, "z label", &z);
39+
p.addTimeGraph("First dynamic addition", 1000, "z label", z);
4040
add_first = false;
4141
}
4242

4343
// After 5 seconds, add a 3-variable graph
4444
if (millis() > 5000 && add_second) {
45-
p.addTimeGraph("Second dynamic addition", 1000, "x label", &x, "y label", &y, "z label", &z);
45+
p.addTimeGraph("Second dynamic addition", 1000, "x label", x, "y label", y, "z label", z);
4646
add_second = false;
4747
}
4848

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
===========================================================================================
3+
Example to demonstrate multi-variable plotting against time
4+
-------------------------------------------------------------------------------------------
5+
Plotter
6+
v1.1.0
7+
https://github.com/devinconley/ArduinoPlotter
8+
by Devin Conley
9+
===========================================================================================
10+
*/
11+
12+
#include "Plotter.h"
13+
14+
// Plotted variables must be declared as globals
15+
double v;
16+
double w;
17+
double x;
18+
double y;
19+
double z;
20+
21+
// Also declare plotter as global
22+
Plotter p;
23+
24+
void setup() {
25+
// Plotter constructor
26+
p = Plotter();
27+
28+
// Add 5 variable time graph
29+
p.addTimeGraph("5 variable time graph", 1000, "v label", v, "w label", w, "x label", x, "y label", y, "z label", z);
30+
31+
}
32+
33+
void loop() {
34+
35+
// Update variables with arbitrary sine/cosine data
36+
v = 3*cos(2.0*PI*(millis()/2500.0));
37+
w = 4.0;
38+
x = 10*sin(2.0*PI*(millis()/5000.0));
39+
y = 7*cos(2.0*PI*(millis()/5000.0));
40+
z = 5*sin(2.0*PI*(millis()/5000.0));
41+
42+
// Plot
43+
p.plot();
44+
}

Plotter/examples/multivariable_plotting/multivariable_plotting.ino

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
Example to demonstrate multi-variable plotting against time
44
-------------------------------------------------------------------------------------------
55
Plotter
6-
v1.0.0
6+
v1.1.0
77
https://github.com/devinconley/ArduinoPlotter
88
by Devin Conley
99
===========================================================================================
10-
*/
10+
*/
1111

1212
#include "Plotter.h"
1313

@@ -26,7 +26,7 @@ void setup() {
2626
p = Plotter();
2727

2828
// Add 5 variable time graph
29-
p.addTimeGraph("5 variable time graph", 1000, "v label", &v, "w label", &w, "x label", &x, "y label", &y, "z label", &z);
29+
p.addTimeGraph("5 variable time graph", 1000, "v label", v, "w label", w, "x label", x, "y label", y, "z label", z);
3030

3131
}
3232

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
===========================================================================================
3+
Example to demonstrate multi-variable plotting against time
4+
-------------------------------------------------------------------------------------------
5+
Plotter
6+
v1.1.0
7+
https://github.com/devinconley/ArduinoPlotter
8+
by Devin Conley
9+
===========================================================================================
10+
*/
11+
12+
#include "Plotter.h"
13+
14+
double x;
15+
double y;
16+
17+
Plotter p;
18+
19+
void setup() {
20+
p = Plotter();
21+
22+
p.addTimeGraph("Some title of single variable graph", 500, "label for x", x);
23+
p.addTimeGraph("Some title of two-variable graph", 500, "label for x", x, "label for y", y);
24+
p.addXYGraph("Title of x versus y graph", 500, "x axis", x, "y axis", y);
25+
}
26+
27+
void loop() {
28+
x = 10*sin(2.0*PI*(millis()/5000.0));
29+
y = 10*cos(2.0*PI*(millis()/5000.0));
30+
31+
p.plot(); // usually called within loop()
32+
}

Plotter/library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=Plotter
2-
version=1.0.1
2+
version=1.1.0
33
author=Devin Conley <devinconley@jhu.edu>
44
maintainer=Devin Conley <devinconley@jhu.edu>
55
sentence=An Arduino library for easy plotting on host computer via serial communication.

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
ArduinoPlotter
22
===============
3-
An Arduino library for easy plotting on host computer via serial communication
3+
An Arduino library for easy graphing on host computer via serial communication
44

55
_by: Devin Conley_
66

@@ -51,14 +51,14 @@ double y;
5151
Plotter p;
5252
```
5353

54-
Create the Plotter object and add graphs as desired. When adding graphs, the first argument is a String with the title of the graph and the second argument is an int with the number of points displayed at any given time. These two arguments are followed by atleast one String and double reference. Include more arguments (in pairs of a String and double reference) to plot multiple variables on a single time graph. If adding an XYGraph, exactly two of these pairs are required.
54+
Create the Plotter object and add graphs as desired. When adding graphs, the first argument is a String with the title of the graph and the second argument is an int with the number of points displayed at any given time. These two arguments are followed by atleast one String and double pair. Include more arguments (in pairs of a String and double) to plot multiple variables on a single time graph. If adding an XYGraph, exactly two of these pairs are required.
5555
```arduino
5656
void setup() {
5757
p = Plotter();
5858
59-
p.addTimeGraph("Some title of single variable graph", 500, "label for x", &x);
60-
p.addTimeGraph("Some title of two-variable graph", 500, "label for x", &x, "label for y", &y);
61-
p.addXYGraph("Title of x versus y graph", 500, "x axis", &x, "y axis", &y);
59+
p.addTimeGraph("Some title of single variable graph", 500, "label for x", x);
60+
p.addTimeGraph("Some title of two-variable graph", 500, "label for x", x, "label for y", y);
61+
p.addXYGraph("Title of x versus y graph", 500, "x axis", x, "y axis", y);
6262
}
6363
```
6464

@@ -79,4 +79,4 @@ Once the Arduino is running, start the listener application that you setup above
7979

8080
The application will auto-configure itself and your data should be plotted appropriately.
8181

82-
__That's it!__
82+
![Quick Start Results Image](https://www.dropbox.com/s/jcosj7sa5uissgh/quickstart_plotted.png?raw=1)

0 commit comments

Comments
 (0)