-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVisualizeSensorSignals.pde
108 lines (98 loc) · 2.49 KB
/
VisualizeSensorSignals.pde
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
//variables
String[] val;
int cur = 0;
int[] xvals,yvals,zvals;
int[] x,y,z;
int flag=0;
//end_variables
void setup() {
//background
size(600, 360);
noSmooth();
stroke(255);
frameRate(60);
//end_background
//load data
val = loadStrings("Accelerometer.txt");
//create arrays for screen data
xvals = new int[width];
yvals = new int[width];
zvals = new int[width];
//create arrays for accelerometer data
x = new int[val.length];
y = new int[val.length];
z = new int[val.length];
//populate the data arrays (x,y,z)
crawlValues();
}
void crawlValues(){
int cur=0;
while (cur < val.length) {
String[] pieces = split(val[cur], ' ');
if (pieces.length == 3) {
x[cur] = int(pieces[0]) * 5;
y[cur] = int(pieces[1]) * 5;
z[cur] = int(pieces[2]) * 5;
}
// Go to the next line for the next run through draw()
cur = cur + 1;
}
}
//extra part
void keyPressed() {
// check if key 'p' is pressed
if (key == 'p' || key == 'P') {
// if it is, we should tell draw function to stop drawing
flag=1;
}
if (key == 'r' || key == 'R') {
// if r is pressed, continue drawing
flag=0;
}
}
void draw() {
//chech if it is paused
if(flag == 0){
//draw background
background(102);
//shift previous screen values
for(int i = 1; i < width; i++) {
xvals[i-1] = xvals[i];
yvals[i-1] = yvals[i];
zvals[i-1] = zvals[i];
}
// Add the new values to the end of the array
xvals[width-1] = x[cur];
yvals[width-1] = y[cur];
zvals[width-1] = z[cur];
//divide the screen to 3 segments for x, y, and z
//white background for the second, others are gray
fill(255);
noStroke();
rect(0, height/3, width, height/3+1);
//print letters 'x','y', and 'z' to the almost middle of the segments
textSize(32);
fill(255);
text("X", 10, height/6);
fill(0);
text("Y", 10, height/2);
fill(255);
text("Z", 10, 5*height/6);
//loop to visualize the data
for(int i=1; i<width; i++) {
stroke(255);
line(i-1,xvals[i-1]/3, i, xvals[i]/3);
stroke(0);
line(i-1, height/3+yvals[i-1]/3,i, height/3+yvals[i]/3);
stroke(255);
line(i-1, 2*height/3+zvals[i-1]/3,i, 2*height/3+zvals[i]/3);
}
//continue to the next data
cur = cur + 1;
//if reached to the end, then stop at the last value
if (cur == val.length)
cur = cur - 1;
textSize(16);
text("Press P to pause, R to continue", 20, height - 20);
}
}