Skip to content

Instantly share code, notes, and snippets.

@pec1985
Created April 27, 2011 02:15
Show Gist options
  • Select an option

  • Save pec1985/943611 to your computer and use it in GitHub Desktop.

Select an option

Save pec1985/943611 to your computer and use it in GitHub Desktop.
pedometer.js
var win = Ti.UI.createWindow({backgroundColor:'#ccc'});
var isRunning = false;
var btn = Ti.UI.createButton({
title:'start',
bottom:10,
height:50,
left:10,
right:10
});
var slider = Ti.UI.createSlider({
width:240,
max:1.0,
min:-1.0,
value:0
});
win.add(slider);
win.add(btn);
win.open({modal:true});
function accel(e){
slider.value = e.x;
}
var stopPedometer = function(){
Titanium.Accelerometer.removeEventListener('update', accel);
}
var startPedometer = function(){
Titanium.Accelerometer.addEventListener('update', accel);
}
btn.addEventListener('click', function(){
if( isRunning ) {
btn.title = 'start';
stopPedometer();
} else {
btn.title = 'stop';
startPedometer();
}
switch(isRunning){
case true: isRunning = false; break;
case false: isRunning = true; break;
}
});
@OscarGodson
Copy link
Copy Markdown

Pedometer? Does that measure the happiness of: http://is.gd/MJB8Ei

@pec1985
Copy link
Copy Markdown
Author

pec1985 commented Apr 27, 2011

Hmmm... well.... LOL

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment