From 435b75170f7aea7c4e7133d8ab0b64cf072f07d3 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 9 May 2012 19:46:15 -0400 Subject: [PATCH] pause button --- fusion1.pde | 11 ++++++++++- imu.pde | 4 ++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/fusion1.pde b/fusion1.pde index 694065f..e73671b 100644 --- a/fusion1.pde +++ b/fusion1.pde @@ -5,6 +5,7 @@ float MPERSSQUARED_PER_BIT = (1/256.0)*9.807; //(g/LSB)*(m*s^-2/g)=m*s^-2/LSB IMU imu; PFont font; +boolean running; class State{ float s; @@ -39,6 +40,13 @@ void keyPressed(){ if(key==' '){ state.s=0; state.v=0; + } else if(key=='p'){ + if(running){ + running=false; + } else { + imu.clear(); + running=true; + } } } @@ -51,11 +59,12 @@ void setup(){ imu = new IMU(this, serialPort); state=null; + running=true; } void draw(){ // until the serial stream runs dry - while(true){ + while(running){ try{ // grab a reading from the IMU diff --git a/imu.pde b/imu.pde index 539357d..64ced16 100644 --- a/imu.pde +++ b/imu.pde @@ -47,6 +47,10 @@ class IMU{ return chunk; } + void clear(){ + serial.clear(); + } + IMUReading read() throws IMUParseException{ String raw = readRaw(); if(raw==null){