Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Examples: modernize example program code syntax
Signed-off-by: Rick Waldron <waldron.rick@gmail.com>
- Loading branch information
Showing
8 changed files
with
122 additions
and
125 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 |
---|---|---|
@@ -1,16 +1,17 @@ | ||
// process.env.IS_TEST_MODE = true; | ||
var Tessel = require("../lib/"); | ||
var board = new Tessel(); | ||
"use strict"; | ||
|
||
board.on("ready", function() { | ||
const Tessel = require("../lib/"); | ||
const board = new Tessel(); | ||
board.on("ready", () => { | ||
console.log("Ready"); | ||
this.pinMode("a7", this.MODES.ANALOG); | ||
this.analogRead("a7", function(data) { | ||
process.stdout.write("\r \033[36mA\033[m " + padLeft(data, 4, 0)); | ||
board.pinMode("a7", board.MODES.ANALOG); | ||
board.analogRead("a7", (data) => { | ||
process.stdout.write(`\r \u001b[36mA\u001b[39m ${padStart(data, 4, 0)}`); | ||
}); | ||
}); | ||
|
||
function padLeft(value, l, c) { | ||
value = String(value); | ||
return Array(l - value.length + 1).join(c || " ") + value; | ||
function padStart(v, l, c) { | ||
v = String(v); | ||
return Array(l - v.length + 1).join(c || " ") + v; | ||
} |
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,15 +1,17 @@ | ||
// process.env.IS_TEST_MODE = true; | ||
var Tessel = require("../lib/"); | ||
var board = new Tessel(); | ||
"use strict"; | ||
|
||
board.on("ready", function() { | ||
const Tessel = require("../lib/"); | ||
const board = new Tessel(); | ||
|
||
board.on("ready", () => { | ||
console.log("Ready"); | ||
|
||
this.pinMode("b0", this.MODES.OUTPUT); | ||
this.digitalWrite("b0", this.HIGH); | ||
board.pinMode("b0", board.MODES.OUTPUT); | ||
board.digitalWrite("b0", board.HIGH); | ||
|
||
setTimeout(function() { | ||
this.digitalWrite("b0", this.LOW); | ||
setTimeout(() => { | ||
board.digitalWrite("b0", board.LOW); | ||
process.exit(0); | ||
}.bind(this), 1000); | ||
}, 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 |
---|---|---|
@@ -1,28 +1,30 @@ | ||
var Tessel = require("../lib/"); | ||
var board = new Tessel(); | ||
"use strict"; | ||
|
||
board.on("ready", function() { | ||
const Tessel = require("../lib/"); | ||
const board = new Tessel(); | ||
|
||
board.on("ready", () => { | ||
console.log("Ready"); | ||
|
||
// LED -> PORT A Pin 5 | ||
this.pinMode("a5", this.MODES.OUTPUT); | ||
board.pinMode("a5", board.MODES.OUTPUT); | ||
// Button -> PORT A Pin 6 | ||
this.pinMode("a6", this.MODES.INPUT); | ||
this.digitalRead("a6", function(data) { | ||
if (this.pins[5].value === 0 && data === 1) { | ||
this.digitalWrite("a5", this.HIGH); | ||
board.pinMode("a6", board.MODES.INPUT); | ||
board.digitalRead("a6", data => { | ||
if (board.pins[5].value === 0 && data === 1) { | ||
board.digitalWrite("a5", board.HIGH); | ||
} else { | ||
if (this.pins[5].value === 1 && data === 0) { | ||
this.digitalWrite("a5", this.LOW); | ||
if (board.pins[5].value === 1 && data === 0) { | ||
board.digitalWrite("a5", board.LOW); | ||
} | ||
} | ||
}); | ||
|
||
// LED -> PORT B Pin 7 | ||
this.pinMode("b7", this.MODES.PWM); | ||
board.pinMode("b7", board.MODES.PWM); | ||
// Potentiometer -> PORT A Pin 7 | ||
this.pinMode("a7", this.MODES.ANALOG); | ||
this.analogRead("a7", function(data) { | ||
this.pwmWrite("b7", data >> 2); | ||
board.pinMode("a7", board.MODES.ANALOG); | ||
board.analogRead("a7", data => { | ||
board.pwmWrite("b7", data >> 2); | ||
}); | ||
}); |
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,15 +1,20 @@ | ||
// process.env.IS_TEST_MODE = true; | ||
var Tessel = require("../lib/"); | ||
var board = new Tessel(); | ||
"use strict"; | ||
|
||
board.on("ready", function() { | ||
const Tessel = require("../lib/"); | ||
const board = new Tessel(); | ||
|
||
board.on("ready", () => { | ||
console.log("Ready"); | ||
|
||
var leds = ["L0", "L1", "L2", "L3"]; | ||
const leds = ["L0", "L1", "L2", "L3"]; | ||
let state = 1; | ||
|
||
|
||
leds.forEach(led => this.digitalWrite(led, this.HIGH)); | ||
leds.forEach(led => board.digitalWrite(led, state)); | ||
|
||
setTimeout(() => { | ||
leds.forEach(led => this.digitalWrite(led, this.LOW)); | ||
setInterval(() => { | ||
state ^= 1; | ||
leds.forEach(led => board.digitalWrite(led, state)); | ||
}, 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,32 @@ | ||
var Tessel = require('../lib/'); | ||
var five = require('johnny-five'); | ||
"use strict"; | ||
|
||
var board = new five.Board({ | ||
io: new Tessel() | ||
}); | ||
|
||
board.on("ready", function(){ | ||
var led = new five.Led.RGB(["a5","a6","b5"]); | ||
const Tessel = require("../lib/"); | ||
const five = require("johnny-five"); | ||
|
||
// use led.<function> in repl | ||
// after color step-through is over | ||
this.repl.inject({ | ||
led: led | ||
}); | ||
var colors = [ | ||
'red', | ||
'orange', | ||
'yellow', | ||
'green', | ||
'blue' | ||
]; | ||
|
||
led.on(); | ||
const board = new five.Board({ | ||
io: new Tessel() | ||
}); | ||
|
||
var index = 0; | ||
this.loop(1000, function(done){ | ||
board.on("ready", () => { | ||
const rgb = new five.Led.RGB(["a5", "a6", "b5"]); | ||
const colors = [ | ||
"red", | ||
"orange", | ||
"yellow", | ||
"green", | ||
"blue" | ||
]; | ||
|
||
if (index >= colors.length){ | ||
led.off(); | ||
done(); | ||
} else { | ||
led.color(colors[index]); | ||
index++; | ||
} | ||
}); | ||
rgb.on(); | ||
|
||
let index = 0; | ||
board.loop(1000, (done) => { | ||
if (index >= colors.length) { | ||
rgb.off(); | ||
done(); | ||
} else { | ||
rgb.color(colors[index]); | ||
index++; | ||
} | ||
}); | ||
}); | ||
|
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,14 +1,16 @@ | ||
// process.env.IS_TEST_MODE = true; | ||
var Tessel = require("../lib/"); | ||
var board = new Tessel(); | ||
"use strict"; | ||
|
||
board.on("ready", function() { | ||
const Tessel = require("../lib/"); | ||
const board = new Tessel(); | ||
|
||
board.on("ready", () => { | ||
console.log("Ready"); | ||
|
||
this.pinMode("a7", this.MODES.ANALOG); | ||
this.pinMode("b7", this.MODES.PWM); | ||
board.pinMode("a7", board.MODES.ANALOG); | ||
board.pinMode("b7", board.MODES.PWM); | ||
|
||
this.analogRead("a7", function(data) { | ||
this.pwmWrite("b7", data >> 2); | ||
board.analogRead("a7", data => { | ||
board.pwmWrite("b7", data >> 2); | ||
}); | ||
}); |