-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
245 additions
and
32 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
var five = require("johnny-five"), | ||
Spark = require("../lib/spark"), | ||
temporal = require("temporal"), | ||
board; | ||
|
||
|
||
// Create Johnny-Five board connected via Spark | ||
board = new five.Board({ | ||
io: new Spark({ | ||
token: process.env.SPARK_TOKEN, | ||
deviceId: process.env.SPARK_DEVICE_ID | ||
}) | ||
}); | ||
|
||
board.on("ready", function() { | ||
var led = new five.Led(process.argv[2] || "D0"); | ||
|
||
this.repl.inject({ | ||
led: led | ||
}); | ||
|
||
temporal.queue([{ | ||
delay: 0, | ||
task: function() { | ||
// on() | ||
// | ||
// Turns the led on | ||
led.on(); | ||
console.log("led on"); | ||
} | ||
}, { | ||
delay: 1000, | ||
task: function() { | ||
// off() | ||
// | ||
// Turns the led off | ||
led.off(); | ||
console.log("led off"); | ||
} | ||
}, { | ||
delay: 3000, | ||
task: function() { | ||
// strobe() | ||
// | ||
// Strobe the led (on/off) | ||
led.strobe(1000); | ||
console.log("led strobe"); | ||
} | ||
}, { | ||
delay: 5000, | ||
task: function() { | ||
// stop() | ||
// | ||
// Stop the pulse | ||
led.stop(); | ||
console.log("led stop"); | ||
|
||
// If you want to make sure it's off | ||
// in case it stopped it while on | ||
led.off(); | ||
} | ||
}, { | ||
delay: 1000, | ||
task: function() { | ||
// fadeIn() | ||
// | ||
// Fade in the led | ||
led.fadeIn(1000); | ||
console.log("led fadeIn"); | ||
} | ||
}, { | ||
delay: 3000, | ||
task: function() { | ||
// fadeOut() | ||
// | ||
// Fade out the led | ||
led.fadeOut(1000); | ||
console.log("led fadeOut"); | ||
} | ||
}, { | ||
delay: 5000, | ||
task: function() { | ||
// brightness () | ||
// | ||
// set analog brightness (0-255) | ||
led.brightness(100); | ||
console.log("led brightness"); | ||
|
||
// Exit gracefully | ||
process.exit(0); | ||
} | ||
} | ||
]); | ||
|
||
|
||
}); | ||
|
||
// @markdown | ||
// To make use of `Led` methods like `fade`, `pulse`, `animate`, you'll need to | ||
// wire an LED to a PWM pin (A0, A1, A4, A5, A6, A7, D0 and D1). | ||
// If you use a different pin, make sure to run the script with the correct pin number: | ||
// | ||
// `node eg/led.js [pinNumber]` | ||
// @markdown |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
var five = require("johnny-five"), | ||
Spark = require("../lib/spark"), | ||
keypress = require("keypress"), | ||
board; | ||
|
||
|
||
// Create Johnny-Five board connected via Spark | ||
board = new five.Board({ | ||
io: new Spark({ | ||
token: process.env.SPARK_TOKEN, | ||
deviceId: process.env.SPARK_DEVICE_ID | ||
}) | ||
}); | ||
|
||
// The board's pins will not be accessible until | ||
// the board has reported that it is ready | ||
board.on("ready", function() { | ||
console.log("CONNECTED"); | ||
|
||
|
||
// Initialize the RGB LED | ||
var led = new five.Led.RGB({ | ||
pins: { | ||
red: "A5", | ||
green: "A6", | ||
blue: "A7" | ||
} | ||
}); | ||
|
||
// RGB LED alternate constructor | ||
// This will normalize an array of pins in [r, g, b] | ||
// order to an object (like above) that's shaped like: | ||
// { | ||
// red: r, | ||
// green: g, | ||
// blue: b | ||
// } | ||
//var led = new five.Led.RGB(["A5","A6","A7"]); | ||
|
||
// Turn it on and set the initial color | ||
led.color("#FF0000"); | ||
|
||
// Listen for user input to change the RGB color | ||
process.stdin.resume(); | ||
process.stdin.setEncoding("utf8"); | ||
process.stdin.setRawMode(true); | ||
|
||
var keymap = { | ||
r: "#FF0000", // red | ||
g: "#00FF00", // green | ||
b: "#0000FF", // blue | ||
w: "#FFFFFF" // white | ||
}; | ||
|
||
process.stdin.on("keypress", function (ch, key) { | ||
|
||
if ( !key ) { | ||
return; | ||
} | ||
|
||
if (keymap[key.name]) { | ||
led.color(keymap[key.name]); | ||
console.log(" ", led.color()); | ||
} else { | ||
led.off(); | ||
} | ||
|
||
}); | ||
|
||
}); | ||
|
||
board.on("error", function(error) { | ||
console.log(error); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
var five = require("johnny-five"), | ||
Spark = require("../lib/spark"), | ||
board; | ||
|
||
|
||
// Create Johnny-Five board connected via Spark | ||
board = new five.Board({ | ||
io: new Spark({ | ||
token: process.env.SPARK_TOKEN, | ||
deviceId: process.env.SPARK_DEVICE_ID | ||
}) | ||
}); | ||
|
||
board.on("ready", function() { | ||
var rgb, rainbow, index; | ||
|
||
|
||
// Initialize the RGB LED | ||
rgb = new five.Led.RGB(["A5", "A6", "A7"]); | ||
rainbow = ["FF000", "FF7F00", "00FF00", "FFFF00", "0000FF", "4B0082", "8F00FF"]; | ||
index = 0; | ||
|
||
setInterval(function() { | ||
if (index + 1 === rainbow.length) { | ||
index = 0; | ||
} | ||
rgb.color(rainbow[index++]); | ||
}, 1000); | ||
|
||
}); |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
var five = require("johnny-five"), | ||
Spark = require("../lib/spark"), | ||
board; | ||
|
||
|
||
// Create Johnny-Five board connected via Spark | ||
board = new five.Board({ | ||
io: new Spark({ | ||
token: process.env.SPARK_TOKEN, | ||
deviceId: process.env.SPARK_DEVICE_ID | ||
}) | ||
}); | ||
|
||
// The board's pins will not be accessible until | ||
// the board has reported that it is ready | ||
board.on("ready", function() { | ||
console.log("CONNECTED"); | ||
|
||
|
||
// Initialize the LED | ||
var led = new five.Led("A5"); | ||
|
||
board.repl.inject({ | ||
led: led | ||
}); | ||
|
||
led.blink(1000); | ||
|
||
}); | ||
|
||
board.on("error", function(error) { | ||
console.log(error); | ||
}); |