• Hi, I have a few puckjs and am looking at how make them into useful household devices. I am currently trying to build a simple to use HID BLE media remote control

    Features

    1. Turn the puck clockwise to raise the volume
    2. Tune the puck anticlockwise to turn down the volume
    3. Tune the puck on its back (black side facing up) then turn to change the channel or track
    4. Click to pause and resume (or Mute /UnMute)

      console.log('Compass heading test');
      Puck.magOn();
      Puck.on('mag', function(c) {
      console.log('Raw mag data: ',c);
      var xGa = c.x * 0.48828125;
      var yGa = c.y * 0.48828125;
      var d = 0;
      if (xGa == 0) {
      if ( yGa <= 0) {
        d = 90;
      } else {
        d = 0;
      }
      } else {
      console.log('Corrected X,YL ',xGa,yGa);
      d = Math.atan(yGa/xGa)*(180/Math.PI);
      }
      if (d > 360) {
      d = d - 360; 
      }
      if (d < 0) {
      d = d + 360;
      }
      console.log('Direction: ', d);
      });
      

    My first attempt is to convert mag x, y, z reading to a compass heading to then take changes to measure left and right rotation. I have completely failed to get this to work any idea what I am doing wrong?

  • Fri 2019.06.28

    Hi @user101436,

    any idea what I am doing wrong?

    Hard to guess what the code is doing, or what you mean by 'doing wrong'. Please post the output as seen by the WebIDE, and the result of process.env for current flash version.

    Although I don't believe this should be an issue, but the examples define the response function, then turn on the mag detection.

    http://www.espruino.com/Puck.js+Door+Lig­ht

About

Avatar for Robin @Robin started