You are reading a single comment by @user130485 and its replies. Click here to read the full conversation.
  • Something like this should help:

    var Vec3 = require("Vec3");
    var magMin = new Vec3();
    var magMax = new Vec3();
    
    Puck.magOn();
    Puck.on('mag', function(xyz) {
      //console.log(xyz); // {x:..., y:..., z:...}
      var v = new Vec3(xyz);
      magMin = magMin.min(v);
      magMax = magMax.max(v);
      var diff = v.sub(magMax.add(magMin).mul(0.5));
      var ang = Math.atan2(diff.y, diff.x)*180/Math.PI;
      console.log(diff, ang);
    });
    

    So that'll output the x/y/z and also an angle (assuming you had the Puck mounted flat against the meter with the magnetometer where the middle of the meter hand is). It'll only do it reliably once the hand has gone around one whole rotation (so it can set up the min/max values).

    Then each time, I guess you just want to check the angle against what it was last time, and if it's moved clockwise then you add that onto what you have for the amount of water that was consumed.

About

Avatar for user130485 @user130485 started