Permalink
Browse files

Throttled sensor example

Signed-off-by: Rick Waldron waldron.rick@gmail.com <waldron.rick@gmail.com>
  • Loading branch information...
1 parent ab9b1b7 commit 8e926823141d5ac122f302399d2e5466affa4541 @rwaldron rwaldron committed Mar 21, 2012
Showing with 43 additions and 3 deletions.
  1. +4 −0 examples/piezo.js
  2. +36 −0 examples/sensor-throttled.js
  3. +2 −2 examples/sensor.js
  4. +1 −1 lib/sensor.js
View
@@ -15,3 +15,7 @@ board.on('ready', function(){
piezo.note('b', 1100);
}, 1000);
});
+
+
+// Resources
+// http://arduino.cc/en/Tutorial/Tone4
@@ -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
View
@@ -12,8 +12,8 @@ sensor = new arduino.Sensor({
sensor.on('read', function(err, value) {
value = +value;
- // |value| is reading of the light dependent resistor
- console.log(value/4);
+ // |value| is the raw sensor output
+ console.log( value );
});
// Tested with:
View
@@ -15,7 +15,7 @@ var Sensor = function (options) {
// Poll for sensor readings
setInterval(function () {
this.board.analogRead(this.pin);
- }.bind(this), 50);
+ }.bind(this), options.throttle || 50);
// When data is received, parse inbound message
// match pin to instance pin value

0 comments on commit 8e92682

Please sign in to comment.