Skip to content

Commit

Permalink
Add support for Tessel Servo module
Browse files Browse the repository at this point in the history
Shorten path to io.name
  • Loading branch information
dtex committed Oct 23, 2015
1 parent 922092f commit 3c9f780
Show file tree
Hide file tree
Showing 7 changed files with 215 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ To interactively navigate the examples, visit the [Johnny-Five examples](http://
### LED
- [LED](https://github.com/rwaldron/johnny-five/blob/master/docs/led.md)
- [LED - PCA9685](https://github.com/rwaldron/johnny-five/blob/master/docs/led-PCA9685.md)
- [LED - Tessel Servo Module](https://github.com/rwaldron/johnny-five/blob/master/docs/led-tessel-servo-module.md)
- [LED - Blink](https://github.com/rwaldron/johnny-five/blob/master/docs/led-blink.md)
- [LED - Pulse](https://github.com/rwaldron/johnny-five/blob/master/docs/led-pulse.md)
- [LED - Pulse with animation](https://github.com/rwaldron/johnny-five/blob/master/docs/led-pulse-animation.md)
Expand Down Expand Up @@ -217,6 +218,7 @@ To interactively navigate the examples, visit the [Johnny-Five examples](http://
### Servo
- [Servo](https://github.com/rwaldron/johnny-five/blob/master/docs/servo.md)
- [Servo - PCA9685](https://github.com/rwaldron/johnny-five/blob/master/docs/servo-PCA9685.md)
- [Servo - Tessel Servo Module](https://github.com/rwaldron/johnny-five/blob/master/docs/servo-tessel-servo-module.md)
- [Servo - Continuous](https://github.com/rwaldron/johnny-five/blob/master/docs/servo-continuous.md)
- [Servo - Slider control](https://github.com/rwaldron/johnny-five/blob/master/docs/servo-slider.md)
- [Servo - Prompt](https://github.com/rwaldron/johnny-five/blob/master/docs/servo-prompt.md)
Expand Down
71 changes: 71 additions & 0 deletions docs/led-tessel-servo-module.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<!--remove-start-->

# LED - Tessel Servo Module

<!--remove-end-->








Run with:
```bash
node eg/led-tessel-servo-module.js
```


```javascript
var five = require("johnny-five");
var Tessel = require("tessel-io");

var board = new five.Board({
io: new Tessel()
});

board.on("ready", function() {
var led = new five.Led({
pin: process.argv[2] || 1,
address: 0x73,
port: "A",
controller: "PCA9685"
});

// address: The address of the shield.
// Defaults to 0x40
// pin: The pin the LED is connected to
// Defaults to 0
// controller: The type of controller being used.
// Defaults to "standard".
// port: The Tessel port being used "A" or "B"

// Add LED to REPL (optional)
this.repl.inject({
led: led
});

led.pulse();
});

```








&nbsp;

<!--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-->
61 changes: 61 additions & 0 deletions docs/servo-tessel-servo-module.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<!--remove-start-->

# Servo - Tessel Servo Module

<!--remove-end-->








Run with:
```bash
node eg/servo-tessel-servo-module.js
```


```javascript
var five = require("johnny-five");
var Tessel = require("tessel-io");

var board = new five.Board({
io: new Tessel()
});

board.on("ready", function() {
console.log("Connected");

// Initialize the servo instance
var servo = new five.Servo({
controller: "PCA9685",
port: "A",
address: 0x73,
pin: 1,
});

servo.sweep();
});

```








&nbsp;

<!--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-->
30 changes: 30 additions & 0 deletions eg/led-tessel-servo-module.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
var five = require("../lib/johnny-five.js");
var Tessel = require("tessel-io");

var board = new five.Board({
io: new Tessel()
});

board.on("ready", function() {
var led = new five.Led({
pin: process.argv[2] || 1,
address: 0x73,
port: "A",
controller: "PCA9685"
});

// address: The address of the shield.
// Defaults to 0x40
// pin: The pin the LED is connected to
// Defaults to 0
// controller: The type of controller being used.
// Defaults to "standard".
// port: The Tessel port being used "A" or "B"

// Add LED to REPL (optional)
this.repl.inject({
led: led
});

led.pulse();
});
20 changes: 20 additions & 0 deletions eg/servo-tessel-servo-module.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
var five = require("../lib/johnny-five.js");
var Tessel = require("tessel-io");

var board = new five.Board({
io: new Tessel()
});

board.on("ready", function() {
console.log("Connected");

// Initialize the servo instance
var servo = new five.Servo({
controller: "PCA9685",
port: "A",
address: 0x73,
pin: 1,
});

servo.sweep();
});
23 changes: 23 additions & 0 deletions lib/expander.js
Original file line number Diff line number Diff line change
Expand Up @@ -661,17 +661,34 @@ var Controllers = {
},
digitalWrite: {
value: function(pin, value) {

// The Tessel Servo module is mislabeled 1 - 16 instead of 0 - 15
if (this.io.name === "Tessel 2") {
pin--;
}

this.pwmWrite(pin, value ? 255 : 0);
}
},
analogWrite: {
value: function(pin, value) {

// The Tessel Servo module is mislabeled 1 - 16 instead of 0 - 15
if (this.io.name === "Tessel 2") {
pin--;
}

this.pwmWrite(pin, value);
}
},
servoWrite: {
value: function(pin, value) {

// The Tessel Servo module is mislabeled 1 - 16 instead of 0 - 15
if (this.io.name === "Tessel 2") {
pin--;
}

value = Board.constrain(value, 0, 180);

var off = __.map(value, 0, 180, this.pwmRange[0] / 4, this.pwmRange[1] / 4);
Expand All @@ -685,6 +702,12 @@ var Controllers = {
},
pwmWrite: {
value: function(pin, value) {

// The Tessel Servo module is mislabeled 1 - 16 instead of 0 - 15
if (this.io.name === "Tessel 2") {
pin--;
}

if (this.pins[pin] === undefined) {
throw new RangeError("Invalid PCA9685 pin: " + pin);
}
Expand Down
8 changes: 8 additions & 0 deletions tpl/programs.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@
"title": "LED - PCA9685",
"description": "Basic LED example using PCA9685"
},
{
"file": "led-tessel-servo-module.js",
"title": "LED - Tessel Servo Module"
},
{
"file": "led-blink.js",
"title": "LED - Blink",
Expand Down Expand Up @@ -274,6 +278,10 @@
"file": "servo-PCA9685.js",
"title": "Servo - PCA9685"
},
{
"file": "servo-tessel-servo-module.js",
"title": "Servo - Tessel Servo Module"
},
{
"file": "servo-continuous.js",
"title": "Servo - Continuous",
Expand Down

0 comments on commit 3c9f780

Please sign in to comment.