Last active
December 22, 2015 00:39
-
-
Save AdamMagaluk/6391169 to your computer and use it in GitHub Desktop.
2013 Arduino Class code
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
var five = require("johnny-five"), | |
// or "./lib/johnny-five" when running from the source | |
board = new five.Board(); | |
board.on("ready", function() { | |
// Create an Led on pin 13 and strobe it on/off | |
// Optionally set the speed; defaults to 100ms | |
(new five.Led(13)).strobe(); | |
}); |
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
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); | |
}); | |
}); |
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
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 ); | |
}); | |
}); |
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
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