-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
2 changed files
with
81 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
<!--remove-start--> | ||
|
||
# Motor - LUDUS | ||
|
||
<!--remove-end--> | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
Run with: | ||
```bash | ||
node eg/motor-LUDUS.js | ||
``` | ||
|
||
|
||
```javascript | ||
var five = require("johnny-five"); | ||
var keypress = require("keypress"); | ||
var board = new five.Board(); | ||
|
||
board.on("ready", function() { | ||
var motors = new five.Motors([ | ||
five.Motor.SHIELD_CONFIGS.SPARKFUN_LUDUS.A, // Left | ||
five.Motor.SHIELD_CONFIGS.SPARKFUN_LUDUS.B, // Right | ||
]); | ||
var speed = 100; | ||
|
||
function controller(ch, key) { | ||
if (key) { | ||
if (key.name === "space") { | ||
motors.stop(); | ||
} | ||
if (key.name === "up") { | ||
motors.fwd(speed); | ||
} | ||
if (key.name === "down") { | ||
motors.rev(speed); | ||
} | ||
if (key.name === "right") { | ||
motors[0].fwd(speed * 0.75); | ||
motors[1].rev(speed * 0.75); | ||
} | ||
if (key.name === "left") { | ||
motors[0].rev(speed * 0.75); | ||
motors[1].fwd(speed * 0.75); | ||
} | ||
} | ||
} | ||
|
||
keypress(process.stdin); | ||
|
||
process.stdin.on("keypress", controller); | ||
process.stdin.setRawMode(true); | ||
process.stdin.resume(); | ||
}); | ||
|
||
``` | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
| ||
|
||
<!--remove-start--> | ||
|
||
## License | ||
Copyright (c) 2012, 2013, 2014 Rick Waldron <waldron.rick@gmail.com> | ||
Licensed under the MIT license. | ||
Copyright (c) 2014, 2015 The Johnny-Five Contributors | ||
Licensed under the MIT license. | ||
|
||
<!--remove-end--> |