Priansh Shah
Published © GPL3+

Smartwatch Game Controller

Control games using your smartwatch!

IntermediateWork in progress1 hour563
Smartwatch Game Controller

Things used in this project

Hardware components

Pebble Watch
Pebble Watch
Any Pebble watch
×1

Software apps and online services

Unity
Unity

Story

Read more

Code

PebbleGyro

JavaScript
This code sends ajax requests to the localhost node.js routing software so that it can be used in Unity to move objects.
var UI = require('ui');
var Accel = require('ui/accel');
Accel.init();
var ajax = require('ajax');
var x; var y; var z;

var main = new UI.Card({
  title: 'UniPebble',
  backgroundColor: 'lavender',
  subtitle: 'Woot!',
  body: 'Sending accel data in realtime!'
});

main.show();
Accel.peek(function(e) {
  console.log('Current acceleration on axis are: X=' + e.accel.x + ' Y=' + e.accel.y + ' Z=' + e.accel.z);
  x = e.accel.x; y = e.accel.y; z = e.accel.z;
});

Accel.on('data', function(e) {
  console.log('Just received ' + e.samples + ' from the accelerometer.');
  var myurl = "http://192.168.1.13:3000/log?x="+(e.accel.x-x)+"&y="+(e.accel.y-y)+"&z="+(e.accel.z-z); //creates new var each time, willfix
  ajax(
  {
    url: myurl,
    type: 'json'
  },
  function(data, status, request) {
    console.log("empty log"); //willfix
  },
  function(error, status, request) {
    console.log('The ajax request failed: ' + error);
  }
);
});

Credits

Priansh Shah

Priansh Shah

3 projects • 7 followers
Hacker/student from Livingston, NJ

Comments

Add projectSign up / Login