Created
February 17, 2016 17:04
-
-
Save jeanfbrito/70419f7ecd2de9da1135 to your computer and use it in GitHub Desktop.
Xadow ADXL345 + OLED display working
This file contains hidden or 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
// Load accelerometer | |
var adxl345 = require('jsupm_adxl345'); | |
// Instantiate on I2C bus | |
var adxl = new adxl345.Adxl345(0); | |
// Initialize the hardware device | |
var screen = new (require("jsupm_i2clcd").SSD1308)(0, 0x3C); | |
// Displays a message on the OLED display | |
function message(msg) { | |
screen.clear(); | |
screen.home(); | |
screen.write(msg); | |
} | |
setInterval(function() | |
{ | |
adxl.update(); // Update the data | |
var raw = adxl.getRawValues(); // Read raw sensor data | |
var force = adxl.getAcceleration(); // Read acceleration force (g) | |
var rawvalues = raw.getitem(0) + " " + raw.getitem(1) + " " + raw.getitem(2); | |
console.log("Raw Values: " + rawvalues); | |
console.log("ForceX: " + force.getitem(0).toFixed(2) + " g"); | |
console.log("ForceY: " + force.getitem(1).toFixed(2) + " g"); | |
console.log("ForceZ: " + force.getitem(2).toFixed(2) + " g"); | |
screen.home(); | |
screen.write(rawvalues + " "); | |
}, 1000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment