Skip to content

Instantly share code, notes, and snippets.

@AdamMagaluk
Last active December 22, 2015 00:39
Show Gist options
  • Save AdamMagaluk/6391169 to your computer and use it in GitHub Desktop.
Save AdamMagaluk/6391169 to your computer and use it in GitHub Desktop.
2013 Arduino Class code
var five = require("johnny-five");
var board = new five.Board();
board.on("ready", function() {
// Create a new `button` hardware instance.
var button = new five.Button(8);
// "down" the button is pressed
button.on("down", function() {
console.log("button down!!");
});
// "up" the button is released
button.on("up", function() {
console.log("button up!!");
});
});
var five = require("johnny-five");
var board = new five.Board();
board.on("ready", function() {
// Create a new `potentiometer` hardware instance.
var potentiometer = new five.Sensor({
pin: "A0",
freq: 250
});
// "read" get the current reading from the potentiometer
potentiometer.on("read", function() {
console.log("Value="+this.value + " Raw Value="+this.raw);
});
});
var five = require("johnny-five"),
board, servo;
board = new five.Board();
board.on("ready", function() {
// Create a new `servo` hardware instance.
servo = new five.Servo(10);
servo.sweep();
// "move" events fire after a successful move.
servo.on("move", function( err, degrees ) {
console.log( "move", degrees );
});
});
var five = require("johnny-five");
var board = new five.Board();
board.on("ready", function() {
// Create a new `potentiometer` hardware instance.
var potentiometer = new five.Sensor({
pin: "A0",
freq: 10
});
var servo = new five.Servo(10);
// "read" get the current reading from the potentiometer
potentiometer.on("read", function() {
// convert [0,1023] -> [-180,180]
var deg = (this.value * 360) / 1023 - 180;
servo.move(deg);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment