• In that case something like this should do it:

    // draw the value to the screen - this could definitely be improved!
    function updateScreen() {
      g.reset();
      g.clearRect(0,100,240,140);
      g.setFontVector(20).setFontAlign(0,0);
      g.drawString(maxValue.toFixed(1),120,120­)
    }
    
    function accelHandler(accel) {
      var t = getTime()-start;
      // get the actual magnitude
      var mag = Math.sqrt(accel.x*accel.x + accel.y*accel.y + accel.z*accel.z);
      // if it's bigger, update the max value and screen
      if (mag > maxValue) {
        maxValue = mag;
        updateScreen();
      }
    }
    
    setWatch(function() {
      // write time and max value
      f.write([
        t*1000,
        maxValue].join(",")+"\n");
      // reset the values
      maxValue = 0;
      updateScreen();
    }, BTN2, {repeat:true});
    
About

Avatar for Gordon @Gordon started