35
36

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

加速度/傾きセンサーの値を取得

Posted at
window.addEventListener("devicemotion", function(evt){
    
    //加速度
    var x = evt.acceleration.x;
    var y = evt.acceleration.y;
    var z = evt.acceleration.z;
    

    //傾き
    var xg = evt.accelerationIncludingGravity.x;
    var yg = evt.accelerationIncludingGravity.y;
    var zg = evt.accelerationIncludingGravity.z;
    
    //回転値
    var a = evt.rotationRate.alpha; //z方向
    var b = evt.rotationRate.beta; //x方向
    var g = evt.rotationRate.gamma; // y方向

    var txt  = "x:"+x+"<br>";
        txt += "y:"+y+"<br>";
        txt += "z:"+z+"<br>";

        txt += "傾きx:"+xg+"<br>";
        txt += "傾きy:"+yg+"<br>";
        txt += "傾きz:"+zg+"<br>";
    
        txt += "alpha(z):"+a+"<br>";
        txt += "beta(x):"+b+"<br>";
        txt += "gamma(y):"+g+"<br>";

    console.log(txt);
   
}, true);
35
36
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
35
36

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?