From 7798923d82d7b8f220c5a01bd66a3f2d22fe490b Mon Sep 17 00:00:00 2001 From: Simon Date: Fri, 11 Jan 2019 15:22:37 +0100 Subject: [PATCH] Add a optional graph for each value --- VMC_Processing_Step1.pde | 49 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/VMC_Processing_Step1.pde b/VMC_Processing_Step1.pde index c33972b..8d99d17 100644 --- a/VMC_Processing_Step1.pde +++ b/VMC_Processing_Step1.pde @@ -1,21 +1,42 @@ import ketai.sensors.*; +// Change this value to disable the Graph +boolean enableGraph = true; KetaiSensor sensor; float fontSize = 130*displayDensity; float accelerometerX, accelerometerY, accelerometerZ, rotationX, rotationY, rotationZ; +ArrayList valuesAccelX = new ArrayList(); +ArrayList valuesAccelY = new ArrayList(); +ArrayList valuesAccelZ = new ArrayList(); +ArrayList valuesRotX = new ArrayList(); +ArrayList valuesRotY = new ArrayList(); +ArrayList valuesRotZ = new ArrayList(); void setup() { sensor = new KetaiSensor(this); sensor.start(); + + textAlign(CENTER, CENTER); textSize(fontSize); + + strokeWeight(6); + smooth(); } float mapNum; void draw() { background(78, 93, 75); + + drawGraph(valuesAccelX, height / 2 - fontSize * 4); + drawGraph(valuesAccelY, height / 2 - fontSize * 3); + drawGraph(valuesAccelZ, height / 2 - fontSize * 2); + drawGraph(valuesRotX, height / 2 + fontSize * 3); + drawGraph(valuesRotY, height / 2 + fontSize * 4); + drawGraph(valuesRotZ, height / 2 + fontSize * 5); + fill(255); text("Accelerometer:", 0, -fontSize*5.5, width, height); mapNum = mapColor(accelerometerX); @@ -44,8 +65,26 @@ float mapColor(float in){ return map(in, -9.83, 9.83, 0, 255); } +void drawGraph(ArrayList values, float margin){ + if(!enableGraph) return; + float lineWidth = (float) width / (values.size() - 1); + for (int i=0; i < values.size() - 1; i++) { + line(i * lineWidth, margin + values.get(i), (i + 1) * lineWidth, margin + values.get(i + 1)); + } +} + void onAccelerometerEvent(float x, float y, float z) { + valuesAccelX.add(int(x * 10)); + while(valuesAccelX.size() > 10) + valuesAccelX.remove(0); + valuesAccelY.add(int(y * 10)); + while(valuesAccelY.size() > 10) + valuesAccelY.remove(0); + valuesAccelZ.add(int(z * 10)); + while(valuesAccelZ.size() > 10) + valuesAccelZ.remove(0); + accelerometerX = x; accelerometerY = y; accelerometerZ = z; @@ -53,6 +92,16 @@ void onAccelerometerEvent(float x, float y, float z) void onGyroscopeEvent(float x, float y, float z) { + valuesRotX.add(int(x * 10)); + while(valuesRotX.size() > 10) + valuesRotX.remove(0); + valuesRotY.add(int(y * 10)); + while(valuesRotY.size() > 10) + valuesRotY.remove(0); + valuesRotZ.add(int(z * 10)); + while(valuesRotZ.size() > 10) + valuesRotZ.remove(0); + rotationX = x; rotationY = y; rotationZ = z;