-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathMyo_3_EMG_Data.pde
73 lines (62 loc) · 1.59 KB
/
Myo_3_EMG_Data.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
import de.voidplus.myo.*;
Myo myo;
ArrayList<ArrayList<Integer>> sensors;
void setup() {
size(800, 400);
background(255);
noFill();
stroke(0);
// ...
myo = new Myo(this, true); // true, with EMG data
sensors = new ArrayList<ArrayList<Integer>>();
for (int i=0; i<8; i++) {
sensors.add(new ArrayList<Integer>());
}
}
void draw() {
background(255);
// ...
// Drawing:
synchronized (this) {
for (int i=0; i<8; i++) {
if (!sensors.get(i).isEmpty()) {
beginShape();
for (int j=0; j<sensors.get(i).size(); j++) {
vertex(j, sensors.get(i).get(j)+(i*50));
}
endShape();
}
}
}
}
// ----------------------------------------------------------
void myoOnEmgData(Device myo, long timestamp, int[] data) {
// println("Sketch: myoOnEmgData, device: " + myo.getId());
// int[] data <- 8 values from -128 to 127
// Data:
synchronized (this) {
for (int i = 0; i<data.length; i++) {
sensors.get(i).add((int) map(data[i], -128, 127, 0, 50)); // [-128 - 127]
}
while (sensors.get(0).size() > width) {
for(ArrayList<Integer> sensor : sensors) {
sensor.remove(0);
}
}
}
}
// ----------------------------------------------------------
/*
void myoOn(Myo.Event event, Device myo, long timestamp) {
switch(event) {
case EMG_DATA:
// println("myoOn EMG & Device: "+myo.getId());
// int[] data <- 8 values from -128 to 127
int[] data = myo.getEmg();
for(int i = 0; i<data.length; i++){
println(map(data[i], -128, 127, 0, 50)); // [-128 - 127]
}
break;
}
}
*/