Skip to content
Rick Waldron edited this page Jul 31, 2013 · 28 revisions

Pin

The Pin class constructs objects that represent any one pin on the physical board.

Parameters

pin A Number or String address for the pin. If digital, use the number, if analog use the "A" prefixed string.

var digital = new five.Pin(13);

var analog = new five.Pin("A0");

options An object of property parameters.

Property Name Description Required
pin The Number or String address of the pin. yes
type "digital" or "analog" no

Usage

API

  • query(callback(value)) Query the board for the current state of this pin, invoking callback with argument state when complete.
var pin = new five.Pin(13);

pin.query(function(state) {
  console.log(state);
});

An example pin state object looks like:

{ 
  supportedModes: [ 0, 1, 3, 4 ],
  mode: 0,
  value: 0,
  report: 1,
  analogChannel: 127 
}

See Modes for supportedModes mapping.

  • high() Set the pin HIGH.
var pin = new five.Pin(13);
// This will set pin 13 high (on)
pin.high();
  • low() Set the pin LOW.
var pin = new five.Pin(13);
// This will set pin 13 low (off)
pin.low();
  • write(value) Write a value to this pin.
var pin = new five.Pin(13);

pin.write(1);
  • read(callback(value)) Register a handler to be called whenever the board reports the value (digital or analog) of this pin.
var pin = new five.Pin(13);

pin.read(function(value) {
  console.log(value);
});

Events

Whenever a pin is set to INPUT, it will automattically emit the following events:

  • high The "high" event is emitted whenever the pin goes high.

  • low The "low" event is emitted whenever the pin goes low.

  • data The "data" event is emitted for every all data (firehose).

Static

Modes

Mode Value Constant
INPUT 0 Pin.INPUT
OUTPUT 1 Pin.OUTPUT
ANALOG 2 Pin.ANALOG
PWM 3 Pin.PWM
SERVO 4 Pin.SERVO

Methods

  • Pin.write(pin, value) Write a value to a pin.
// This will set pin 13 High
five.Pin.write(13, 1);
  • Pin.read(pin, value) Register a handler to be called whenever the board reports the value (digital or analog) of the specified pin.
five.Pin.read(13, function(value) {
  console.log(value);
});
Clone this wiki locally