Paul Langdon
Published

Example: Rotary Angle Sensor

Sample Rotary Angle Sensor on Intel Edison in Node.js

BeginnerProtip729
Example: Rotary Angle Sensor

Code

Read rotary sensor and write to console

JavaScript
//setup/Initialization
var upm_grove = require('jsupm_grove');

//setup access analog input Analog pin #0 (A0)
var groveRotary = new upm_grove.GroveRotary(0);

loop();

function loop()
{
    var abs = groveRotary.abs_value();
    var absdeg = groveRotary.abs_deg();
    var absrad = groveRotary.abs_rad();

    var rel = groveRotary.rel_value();
    var reldeg = groveRotary.rel_deg();
    var relrad = groveRotary.rel_rad();

    //write the knob value to the console in different formats
    console.log("Abs: " + abs + " " + Math.round(parseInt(absdeg)) + " " + absrad.toFixed(3));
    console.log("Rel: " + rel + " " + Math.round(parseInt(reldeg)) + " " + relrad.toFixed(3));

    //wait 2 s and call function again
    setTimeout(loop, 2000);
}

Credits

Paul Langdon

Paul Langdon

49 projects • 316 followers
Working as a cloud architect for an IoT hardware company

Comments