http://bit.ly/ becoming-a-maker
A microcontroller is a small computer on a single integrated circuit containing a processor core, memory, and programmable input/output peripherals.
npm init (follow prompts)
npm install --save johnny-five
var five = require('johnny-five');
var board = new five.Board();
board.on('ready', function() {
var led = new five.Led(11);
// This will grant access to the led instance
// from within the REPL that's created when
// running this program.
this.repl.inject({
led: led
});
led.blink();
});
var five = require('johnny-five');
var board = new five.Board();
var button;
var led;
board.on('ready', function() {
led = new five.Led(11);
// Create a new `button` hardware instance.
// This example allows the button module to
// create a completely default instance
button = new five.Button(2);
// Inject the `button` hardware into
// the Repl instance's context;
// allows direct command line access
board.repl.inject({
button: button,
led: led
});
// Button Event API
// "down" the button is pressed
button.on('down', function() {
console.log('down');
led.brightness(255);
});
button.on('hold', function() {
console.log('hold');
led.blink(500);
});
// "up" the button is released
button.on('up', function() {
console.log('up');
led.stop(); // Stops the blinking
led.brightness(0);
});
});
var five = require('johnny-five');
var board = new five.Board();
board.on('ready', function() {
var range = [
0,
180
];
// Servo to control panning
var pan = new five.Servo({
pin: 9,
range: range
});
// Servo to control tilt
var tilt = new five.Servo({
pin: 10,
range: range
});
// Joystick to control pan/tilt
// Read Analog 0, 1
// Limit events to every 100ms
var joystick = new five.Joystick({
pins: [
'A0',
'A1'
],
freq: 100
});
tilt.center();
pan.center();
joystick.on('change', function() {
console.log('y: ', this.y);
console.log('x: ', this.x);
tilt.to(five.Fn.scale(this.y, -1, 1, 0, 170));
pan.to(five.Fn.scale(this.x, -1, 1, 0, 170));
});
});
npm install -g t2-cli
t2 init (in project folder)
npm install --save johnny-five tessel-io