Skip to content

Instantly share code, notes, and snippets.

@rwaldron
Last active Aug 29, 2015
Embed
What would you like to do?
Alternate Light Bot programs
var Imp = require("imp-io");
var five = require("johnny-five");
var Sumobot = require("sumobot")(five);
var board = new five.Board({
io: new Imp({
agent: "agent id"
})
});
board.on("ready", function() {
console.log("Welcome to Sumobot Jr: Light Bot!");
var bot = new Sumobot({
left: 1,
right: 2,
speed: 0.50
});
var light = new five.Sensor(5);
// More light => higher resistance => lower ADC value
// If the reading is < 512, it's in direct light
light.booleanAt(512).on("data", function() {
bot[this.boolean ? "stop" : "fwd"]();
});
// Ensure the bot is stopped
bot.stop();
});
var five = require("../");
var Sumobot = require("sumobot")(five);
var board = new five.Board();
board.on("ready", function() {
console.log("Welcome to Sumobot Jr: Light Bot!");
var bot = new Sumobot({
left: 9,
right: 10,
speed: 0.50
});
var light = new five.Sensor("A0");
// More light => higher resistance => lower ADC value
// If the reading is < 512, it's in direct light
light.booleanAt(512).on("data", function() {
bot[this.boolean ? "stop" : "fwd"]();
});
// Ensure the bot is stopped
bot.stop();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment