-
Notifications
You must be signed in to change notification settings - Fork 0
Ping
The 'Ping' class constructs an object that represents a single sonar ping sensor.
-
pin A Number or String address for the ping sensor
-
options An object of property parameters.
Property Name | Type | Value(s) | Description | Required |
---|---|---|---|---|
pin | Number, String | 9, "I1" (Any digital pin on board) | The Number or String address of the pin the sensor is attached to, ie. 7 | yes |
freq | Number | Milliseconds | The frequency in ms of read events. Defaults to 100ms | no |
pulse | Number | Milliseconds | The frequency in ms of pulses. Defaults to 500ms | no |
{
pin: The pin address that the Ping Sensor is attached to.
freq: The frequency of read events.
pulse: The frequency of pulses.
inches: The detected distance in inches. READONLY
cm: The detected distance in centimetres. READONLY
}
var five = require("johnny-five"),
board = new five.Board();
board.on("ready", function() {
//Create new Ping and show distance on change
var ping = new five.Ping(7);
ping.on("change", function( err, value ) {
console.log('Object is ' + this.cm + ' cm away');
console.log('Object is ' + this.inches + ' inches away');
});
});
Ping does not have any API functions
-
change The "change" event is emitted whenever the distance detected by the sensor changes more then the threshold value allows.
-
data The "data" event is fired as frequently as the user defined freq will allow in milliseconds. ("data" replaced the "read" event)
Ping requires a specific version of firmata to be loaded onto the Arduino in order to work.
If you have the Arduino IDE open, you should close it before you start.
First get to the following directory with your Terminal or Git command line:
OS X:
/Applications/Arduino.app/Contents/Resources/Java/libraries/
Linux:
/usr/share/arduino/libraries/
Windows:
C:\Program Files (x86)\Arduino\libraries\
Then proceed with the following in your command line:
# make a backup of the existing Firmata
cp -r Firmata Firmata_stable
# rm Firmata
rm -r Firmata
# clone the experimental repo branch
git clone git://github.com/jgautier/arduino-1.git Firmata
# enter!
cd Firmata
# get the branch with pulseIn
git checkout -b pulseIn origin/pulseIn
Now open the Arduino IDE.
-
File > Examples > Firmata > Standard Firmata
-
Once that's loaded into the IDE, confirm it is the correct program by searching for "PULSE_IN".
-
You should now be able to Compile and upload this version of Standard Firmata to your Arduino.
If you receive an error about PULSE_IN not being in scope, then copy this:
#define PULSE_IN 0x74 // send a pulse in command
And add it below the following line:
#define REGISTER_NOT_SPECIFIED -1