LoginSignup
2
1

More than 5 years have passed since last update.

やっとモーションセンサー使えた

Last updated at Posted at 2018-04-12

煮詰まったので、Monacaにログインしてローカルで書いたコードをコピペして、デバッグしていました。
デバッグのログが対辺見やすく、デバッグが捗りました。

その結果、センサーで下記のコードを書いたら動きました。

        function onDeviceReady(){
            console.log("センサーが使えるようになりました!");
        }

そして

ons.ready(function test2() {

    // CordovaのAPIを呼び出す準備が整った


    //加速度センサー 更新時間
    var options = { frequency: 1000 };  // 1秒ごとに更新

    //センサー戻り値
    watchID = navigator.accelerometer.watchAcceleration(onSuccess, onError, options);

  });

と続けて書いたら、無事にセンサー動きました。

センサーの停止も加えました。

    //センサー停止
    navigator.accelerometer.clearWatch(watchID);

Visualstudioのブラウザのエミュレーションでも、センサーを使うことが出来ました。
キャプチャ-センサー.PNG

Monacaでは、HTML5の音声合成のAPIを使うことが出来ないです。
また、私は無料プランなので、Cordova TTSのプラグインを加えることが出来ないので、ローカルで開発を続けます。

でも、8割くらいようやく完成したので、良かったです。

2
1
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
2
1