Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from rwldrn/ldr
Adds Sensor module for reading arbitrary input sensors
- Loading branch information
Showing
15 changed files
with
652 additions
and
85 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 +1,2 @@ | ||
node_modules | ||
.DS_Store | ||
node_modules |
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,31 @@ | ||
var arduino = require('../'), | ||
board, ping; | ||
|
||
board = new arduino.Board({ | ||
debug: false | ||
}); | ||
|
||
ping = new arduino.Ping({ | ||
board: board, | ||
pin: 7 | ||
}); | ||
|
||
// 'read' events fire approx ~50ms | ||
ping.on('read', function(err) { | ||
|
||
// Current sensor data stored in properties | ||
// of this Ping instance: | ||
// | ||
// this.microseconds - time lapse from fire to read | ||
// this.inches - calculated distance to object in inches | ||
// this.centimeters - calculated distance to object in centimeters | ||
|
||
console.log('Object is ~' + Math.round(this.inches) + ' inches from sensor'); | ||
|
||
}); | ||
|
||
// To test, use the following: | ||
// http://arduino.cc/en/uploads/Tutorial/ping_bb.png | ||
// | ||
// More information: | ||
// http://arduino.cc/en/Tutorial/Ping |
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,52 @@ | ||
var arduino = require('../'), | ||
board, pir; | ||
|
||
board = new arduino.Board({ | ||
debug: false | ||
}); | ||
|
||
pir = new arduino.PIR({ | ||
board: board, | ||
pin: 7 | ||
}); | ||
|
||
// 'calibrated' event fired when PIR sensor is | ||
// ready to detect movement/motion in observable range | ||
// | ||
// All events receive error and date arguments | ||
pir.on('calibrated', function(err, date) { | ||
|
||
console.log('calibrated'); | ||
|
||
// Current sensor data stored in properties | ||
// of this PIR instance: | ||
// | ||
// this.state - current state of motion | ||
// 0 No motion currently detected | ||
// 1 Motion currently detected | ||
|
||
// 'motionstart' event fired when motion occurs | ||
// within the observable range of the PIR sensor | ||
this.on('motionstart', function(err, date) { | ||
|
||
console.log('motionstart', this.state); | ||
console.log( date ); | ||
|
||
}); | ||
|
||
// 'motionend' event fired when motion has ceased | ||
// within the observable range of the PIR sensor | ||
this.on('motionend', function(err, date) { | ||
|
||
console.log('motionend', this.state); | ||
|
||
}); | ||
}); | ||
|
||
|
||
// To test, use the following: | ||
// http://www.ladyada.net/images/sensors/pirardbb.gif | ||
// http://bildr.org/blog/wp-content/uploads/2011/06/PIR-Arduino_hookup.png | ||
// | ||
// More information: | ||
// http://www.ladyada.net/learn/sensors/pir.html |
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,36 @@ | ||
var arduino = require('../'), | ||
board, sensor, piezo; | ||
|
||
board = new arduino.Board({ | ||
debug: false | ||
}); | ||
|
||
sensor = new arduino.Sensor({ | ||
board: board, | ||
pin: 'A0', | ||
throttle: 100 | ||
}); | ||
|
||
piezo = new arduino.Piezo({ | ||
board: board, | ||
pin: 11 | ||
}); | ||
|
||
sensor.on('read', function(err, value) { | ||
value = +value; | ||
|
||
// |value| is the raw sensor output | ||
console.log( value ); | ||
|
||
if ( value > 0 ) { | ||
piezo.note('b', 100); | ||
} | ||
}); | ||
|
||
// Tested with: | ||
// SoftPot | ||
// http://www.spectrasymbol.com/how-it-works-softpot | ||
// http://www.sparkfun.com/datasheets/Sensors/Flex/SoftPot-Datasheet.pdf | ||
// | ||
// sensor | ||
// http://www.ladyada.net/learn/sensors/cds.html |
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,25 @@ | ||
var arduino = require('../'), | ||
board, sensor; | ||
|
||
board = new arduino.Board({ | ||
debug: true | ||
}); | ||
|
||
sensor = new arduino.Sensor({ | ||
board: board, | ||
pin: 'A0' | ||
}); | ||
|
||
sensor.on('read', function(err, value) { | ||
value = +value; | ||
// |value| is the raw sensor output | ||
console.log( value ); | ||
}); | ||
|
||
// Tested with: | ||
// SoftPot | ||
// http://www.spectrasymbol.com/how-it-works-softpot | ||
// http://www.sparkfun.com/datasheets/Sensors/Flex/SoftPot-Datasheet.pdf | ||
// | ||
// sensor | ||
// http://www.ladyada.net/learn/sensors/cds.html |
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,13 +1,56 @@ | ||
var arduino = require('../'); | ||
var arduino = require('../'), | ||
board, led, servo; | ||
|
||
var board = new arduino.Board({ | ||
// Construct instances | ||
board = new arduino.Board({ | ||
debug: true | ||
}); | ||
|
||
var servo = new arduino.Servo({ | ||
board: board | ||
led = new arduino.Led({ | ||
board: board, | ||
pin: 13 | ||
}); | ||
|
||
board.on('ready', function(){ | ||
servo.sweep(); | ||
servo = new arduino.Servo({ | ||
board: board, | ||
pin: 9 | ||
}); | ||
|
||
// Once servo is attached: | ||
// - "read" | ||
// - log position | ||
// - "aftersweep" | ||
// - blink the led | ||
// - read the position | ||
// - detach the servo | ||
// - "detached" | ||
// - log detach message | ||
// | ||
// - execute full sweep | ||
|
||
servo.on('attached', function(err) { | ||
console.log('attached'); | ||
|
||
this.on('read', function(err, pos) { | ||
console.log(pos); | ||
}); | ||
|
||
this.on('detached', function(err) { | ||
console.log('detached'); | ||
}); | ||
|
||
this.on('aftersweep', function(err) { | ||
led.blink(); | ||
|
||
this.read(); | ||
this.detach(); | ||
}); | ||
|
||
this.sweep(); | ||
}); | ||
|
||
// To test, use the following: | ||
// http://arduino.cc/en/uploads/Tutorial/sweep_BB.png | ||
// | ||
// More information: | ||
// http://www.ladyada.net/learn/sensors/pir.html |
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
Oops, something went wrong.