Skip to content

Commit

Permalink
Throttled sensor example
Browse files Browse the repository at this point in the history
Signed-off-by: Rick Waldron waldron.rick@gmail.com <waldron.rick@gmail.com>
  • Loading branch information
rwaldron committed Mar 21, 2012
1 parent ab9b1b7 commit 8e92682
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 3 deletions.
4 changes: 4 additions & 0 deletions examples/piezo.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -15,3 +15,7 @@ board.on('ready', function(){
piezo.note('b', 1100); piezo.note('b', 1100);
}, 1000); }, 1000);
}); });


// Resources
// http://arduino.cc/en/Tutorial/Tone4
36 changes: 36 additions & 0 deletions examples/sensor-throttled.js
Original file line number Original file line 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
4 changes: 2 additions & 2 deletions examples/sensor.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ sensor = new arduino.Sensor({


sensor.on('read', function(err, value) { sensor.on('read', function(err, value) {
value = +value; value = +value;
// |value| is reading of the light dependent resistor // |value| is the raw sensor output
console.log(value/4); console.log( value );
}); });


// Tested with: // Tested with:
Expand Down
2 changes: 1 addition & 1 deletion lib/sensor.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var Sensor = function (options) {
// Poll for sensor readings // Poll for sensor readings
setInterval(function () { setInterval(function () {
this.board.analogRead(this.pin); this.board.analogRead(this.pin);
}.bind(this), 50); }.bind(this), options.throttle || 50);


// When data is received, parse inbound message // When data is received, parse inbound message
// match pin to instance pin value // match pin to instance pin value
Expand Down

0 comments on commit 8e92682

Please sign in to comment.