I'm an arduino noob and I'm trying to interface some javascript with arduino. For now all I'm trying to do is move a servomotor in a direction if a js variable is under a certain value and moving it the other way if it's above that value. I don't have a clue about how i should tackle this, so I'd appreciate any help. I do have the servomotor moving part and the javascript part, I just don't know how to put them together.
For now all I'm trying to do is move a servomotor in a direction if a js variable is under a certain value and moving it the other way if it's above that value.
Here's how you can accomplish this with Johnny-Five:
npm install johnny-five
var five = require("johnny-five");
var board = new five.Board();
board.on("ready", function() {
var servo = new five.Servo(11);
this.repl.inject({
move: function(value) {
var angle = 0;
if (value > 0) {
angle = 180;
}
servo.to(angle);
}
});
});
move(n)
where n
is any number. Numbers greater than 0 will move the servo to 180°; numbers less than or equal to 0 will move the servo to 0°.