You are reading a single comment by @user110429 and its replies. Click here to read the full conversation.
  • Hi all,

    I'm working on a project where I use the puck.js to keep track of reps based on the difference of the starting value returned by the magnetometer and the elevated value when users complete a rep.

    Currently I'm using a hardcoded value for comparison, but I don't like this approach. I want to be able to either read the previous value obtained by the magnetometer or at least get some help with storing the value for later use.

    Any help is much appreciated.

    var zero = Puck.mag();
    var doorOpen = false;
     var isRep = false;
    function onMag(p) {
      p.x -= zero.x;
      p.y -= zero.y;
      p.z -= zero.z;
      var s = Math.sqrt(p.x*p.x + p.y*p.y + p.z*p.z);
      var h = Math.floor(s);
      console.log(h);
      
      console.log(isRep);
    
      if(!isRep){
        if (h > 500){
          isRep = true;
          console.log("Rep counted"); 
       }
      }
    }
    
    Puck.on('mag', onMag);
    Puck.magOn();
    
    
    
About

Avatar for user110429 @user110429 started