Created
March 29, 2014 19:33
-
-
Save soundanalogous/9861403 to your computer and use it in GitHub Desktop.
BMA250 example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset=utf-8 /> | |
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"> | |
<style type="text/css"> | |
body { | |
margin: 15px; | |
font-family: sans-serif; | |
font-size: 16px; | |
line-height: 1.5em; | |
color: #666; | |
} | |
h2 { | |
padding-left: 0px; | |
font-weight: normal; | |
font-size: 22px; | |
color: #00AEFF; | |
} | |
.container { | |
background-color: #f7f7f7; | |
border: 1px dotted #CCC; | |
width: 290px; | |
margin-top: 40px; | |
} | |
.text { | |
font-family: "Arial"; | |
font-size: 22px; | |
color: #666; | |
padding: 20px; | |
margin: 0; | |
} | |
</style> | |
<title>BMA250 Accelerometer Example</title> | |
<!-- The following (socket.io.js) is only required when using the node_server --> | |
<script src="../../socket.io/socket.io.js"></script> | |
<script src="../../dist/Breakout.min.js"></script> | |
<script src="path/to/AccelerometerBMA250.js"></script> | |
<script src="../libs/jquery.min.js"></script> | |
<script type="text/javascript"> | |
$(document).ready(function() { | |
// Declare these variables so you don't have | |
// to type the full namespace | |
var IOBoard = BO.IOBoard; | |
var IOBoardEvent = BO.IOBoardEvent; | |
var AccelerometerBMA250 = BO.io.AccelerometerBMA250; | |
var AccelerometerEvent = BO.io.AccelerometerEvent; | |
// Set to true to print debug messages to console | |
BO.enableDebugging = true; | |
// If you are not serving this file from the same computer | |
// that the Arduino board is connected to, replace | |
// window.location.hostname with the IP address or hostname | |
// of the computer that the Arduino board is connected to. | |
var host = window.location.hostname; | |
// if the file is opened locally, set the host to "localhost" | |
if (window.location.protocol.indexOf("file:") === 0) { | |
host = "localhost"; | |
} | |
var fio = new IOBoard(host, 8887); | |
// Listen for the IOBoard READY event which indicates the IOBoard | |
// is ready to send and receive data | |
fio.addEventListener(IOBoardEvent.READY, onReady); | |
function onReady(event) { | |
// Remove the event listener because it is no longer needed | |
fio.removeEventListener(IOBoardEvent.READY, onReady); | |
// Params: IOBoard, dynamicRange, bandwidth, i2cAddress | |
// var accelerometer = new AccelerometerBMA250( | |
// fio, | |
// AccelerometerBMA250.RANGE_2G, | |
// AccelerometerBMA250.BAND_7_81HZ, | |
// AccelerometerBMA250.DEVICE_ID); | |
// Using default settings | |
var accelerometer = new AccelerometerBMA250(fio); | |
// Start continuous reading of the accelerometer | |
accelerometer.startReading(); | |
accelerometer.addEventListener(AccelerometerEvent.UPDATE, onAccelerationUpdate); | |
} | |
function onAccelerationUpdate(event) { | |
var accel = event.target; | |
// Display the accelerometer values in the browser | |
$('#xVal').html("x = " + accel.rawX); | |
$('#yVal').html("y = " + accel.rawY); | |
$('#zVal').html("z = " + accel.rawZ); | |
} | |
}); | |
</script> | |
</head> | |
<body> | |
<h2>BMA250 Accelerometer</h2> | |
<div class="container"> | |
<div id="xVal" class="text">x =</div> | |
<div id="yVal" class="text">y =</div> | |
<div id="zVal" class="text">z =</div> | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment