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
14 changed files
with
384 additions
and
496 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
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
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 |
---|---|---|
@@ -1,16 +1,17 @@ | ||
var five = require("../lib/johnny-five.js"); | ||
var board = new five.Board(); | ||
const {Board, ESC, Sensor} = require("../lib/johnny-five.js"); | ||
const board = new Board(); | ||
|
||
board.on("ready", function() { | ||
|
||
var esc = new five.ESC({ | ||
const esc = new ESC({ | ||
controller: "PCA9685", | ||
device: "FORWARD", | ||
pin: 1 | ||
}); | ||
|
||
var pot = new five.Sensor("A0"); | ||
const pot = new Sensor("A0"); | ||
|
||
pot.scale(0, 100).on("change", function() { | ||
esc.speed(this.value); | ||
pot.on("change", () => { | ||
esc.throttle(pot.scaleTo(esc.pwmRange)); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -1,16 +1,13 @@ | ||
var five = require("../lib/johnny-five.js"); | ||
var board = new five.Board(); | ||
const {Board, ESC} = require("../lib/johnny-five.js"); | ||
const board = new Board(); | ||
|
||
board.on("ready", function() { | ||
|
||
var escs = new five.ESCs([9, 10]); | ||
const escs = new ESC.Collection([9, 10]); | ||
|
||
// Set the motors to their max speed | ||
escs.max(); | ||
|
||
board.wait(2000, function() { | ||
// Set the motors to the min speed (stopped) | ||
escs.min(); | ||
}); | ||
// This might be dangerous ¯\_(ツ)_/¯ | ||
escs.throttle(100); | ||
|
||
board.wait(2000, () => escs.brake()); | ||
}); |
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 |
---|---|---|
@@ -1,28 +1,19 @@ | ||
var five = require("../"); | ||
var board = new five.Board(); | ||
const {Board, Button, ESC, Sensor} = require("../"); | ||
const board = new Board(); | ||
|
||
board.on("ready", function() { | ||
var start = Date.now(); | ||
var esc = new five.ESC({ | ||
const esc = new ESC({ | ||
device: "FORWARD_REVERSE", | ||
neutral: 50, | ||
pin: 11 | ||
}); | ||
var throttle = new five.Sensor("A0"); | ||
var brake = new five.Button(4); | ||
const throttle = new Sensor("A0"); | ||
const brake = new Button(4); | ||
|
||
brake.on("press", function() { | ||
brake.on("press", () => { | ||
esc.brake(); | ||
}); | ||
|
||
throttle.scale(0, 100).on("change", function() { | ||
// 2 Seconds for arming. | ||
if (Date.now() - start < 2e3) { | ||
return; | ||
} | ||
|
||
if (esc.value !== this.value) { | ||
esc.speed(this.value); | ||
} | ||
throttle.on("change", () => { | ||
esc.throttle(throttle.scaleTo(esc.pwmRange)); | ||
}); | ||
}); |
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,57 @@ | ||
const {Board, ESC, Fn, Led} = require("../lib/johnny-five.js"); | ||
const keypress = require("keypress"); | ||
|
||
const board = new Board(); | ||
|
||
board.on("error", error => { | ||
console.error(error); | ||
process.exit(1); | ||
}); | ||
|
||
board.on("ready", () => { | ||
const led = new Led(13); | ||
const esc = new ESC({ | ||
device: "FORWARD_REVERSE", | ||
pin: 11, | ||
}); | ||
let speed = 0; | ||
let last = null; | ||
|
||
// just to make sure the program is running | ||
led.blink(500); | ||
|
||
function controller(_, key) { | ||
let change = 0; | ||
|
||
if (key) { | ||
if (!key.shift) { | ||
change = esc.neutral; | ||
speed = 0; | ||
} else { | ||
if (key.name === "up" || key.name === "down") { | ||
if (last !== key.name) { | ||
change = esc.neutral; | ||
speed = 0; | ||
} else { | ||
speed += 1; | ||
|
||
change = key.name === "up" ? | ||
esc.neutral + speed : | ||
esc.neutral - speed; | ||
} | ||
last = key.name; | ||
} | ||
} | ||
|
||
if (change) { | ||
esc.throttle(change); | ||
} | ||
} | ||
} | ||
|
||
keypress(process.stdin); | ||
|
||
process.stdin.on("keypress", controller); | ||
process.stdin.setRawMode(true); | ||
process.stdin.resume(); | ||
}); |
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
Oops, something went wrong.