Avatar for Charly86

Charly86

Member since Jun 2017 • Last active Jun 2017
  • 0 conversations
  • 2 comments

Most recent activity

  • in Puck.js, Pixl.js and MDBT42
    Avatar for Charly86

    @Gordon
    Thanks, I missed this one
    I tried something similar with start/stop movement detection with button, when pressed, Green led indicate it's on and then blink Red in case of movement. another push stop detection by blue blink
    New position is saved like this moving and leaving puckjs to another place will stop detection until it's moved again. Seems to works, need to play with threeshold.
    Here the code, I'll try your since your math detection looks better than mine ;)

    var th = 10;
    var x =0;
    var y =0;
    var z =0;
    var accFirstRead = true;
    var acc = false;
    
    Puck.magOff();
    
    function doJob(x,y,z) {
      var b = Puck.getBatteryPercentage();
      var t = E.getTemperature();
      var l = Puck.light()*100 ;
      console.log("Batt", b, "  Temp",t, "  Light",t );
      console.log("Diff X:",x, " Y:",y, "Z:",z);
    }
    
    setWatch(function() {
      if (acc) {
        Puck.magOff();
        acc = false;
        digitalPulse(LED3, 1, 100);
        console.log("Accel OFF");
      } else {
        accFirstRead = true;
        acc = true;
        //Puck.magOn(0.31);
        Puck.magOn();
        digitalPulse(LED2, 1, 100);
        console.log("Accel ON");
      }
    }, BTN, {edge:"rising", debounce:50, repeat:true});
    
    Puck.on('mag', function(xyz) {
      var diffx = xyz.x-x;
      var diffy = xyz.y-y;
      var diffz = xyz.z-z;
      x = xyz.x;
      y = xyz.y;
      z = xyz.z;
      //digitalPulse(LED3, 1, 5);
      //console.log(xyz);
      //doJob(xyz);
    
      if (accFirstRead) {
        accFirstRead = false;
        doJob(x,y,z);
      } else {
        if (Math.abs(diffx)>th || Math.abs(diffy)>th*2 || Math.abs(diffz)>th*2) {
          digitalPulse(LED1, 1, 250);
          doJob(diffx, diffy, diffz);
        } else {
          //console.log("Diff X:",diffx, " Y:",diffy, "Z:",diffz);
        }
      }
    });
    
  • in Puck.js, Pixl.js and MDBT42
    Avatar for Charly86

    @Gordon
    I'm new to puck js and this is just an amazing device, I'm glad with it and get it working in less than 5 minutes.
    Working everyday with ESP32, Lopy, Sodaq and LoraWan devices, your little puck open me new doors for business.
    I usually use accelerometer with IRQ detection with programmed thresold to get IRQ only when device is moved.
    So according this post it's not possible yet, so what's the best deal to detect move of the device with best consumption usage ? (compare values between wakes ?)
    Any example code would be welcome
    thanks for your help

Actions