r-pi-brick
A Node.js API for the BrickPi.
Getting Started
Installation
npm install r-pi-brick --save
Integration
var brick = ;
API
Overview
- Events
- brick.init([maxRetries])
- brick.isMotorEnabled(port)
- brick.setMotorEnabled(enabled, port)
- brick.getMotorPosition(port)
- brick.getMotorPower(port)
- brick.setMotorPower(power, port)
- brick.getMotorSpeed(port)
- brick.MOTOR_PORT_A
- brick.MOTOR_PORT_B
- brick.MOTOR_PORT_C
- brick.MOTOR_PORT_D
Events
error
Event
The brick;
init
Event
The brick;
update
Event
The brick;
brick.init([maxRetries])
Initializes the serial connection to the BrickPi. Updates all brick values, every 10 ms, via the serial connection. Retries an update if a serial communication timeout occurs. The number of maximum retries has a default value of 3.
Emits an error if the number of maximum retries is exceeded.
brick;
brick.isMotorEnabled(port)
Returns the enabled flag of the motor plugged into the specified port.
var enabledA = brick;var enabledB = brick; var enabledC = brick;var enabledD = brick;
brick.setMotorEnabled(enabled, port)
Sets the enabled flag of the motor plugged into the specified port.
brick;brick; brick;brick;
brick.getMotorPosition(port)
Returns the position of the motor, in 0.5-degree increments, plugged into the specified port. The position is an integer in the range of -1073741823 to 1073741823. Divide by 2 to get degrees.
var positionA = brick;var positionB = brick; var positionC = brick;var positionD = brick;
brick.getMotorPower(port)
Returns the power of the motor plugged into the specified port. The power is an integer in the range of -100 to 100.
var powerA = brick;var powerB = brick; var powerC = brick;var powerD = brick;
brick.setMotorPower(power, port)
Sets the power of the motor plugged into the specified port. The power must be an integer in the range of -100 to 100.
brick;brick; brick;brick;
brick.getMotorSpeed(port)
Returns the speed of the motor, in degrees per second, plugged into the specified port.
var speedA = brick;var speedB = brick; var speedC = brick;var speedD = brick;
brick.MOTOR_PORT_A
This port should be used together with port B.
brick.MOTOR_PORT_B
This port should be used together with port A.
brick.MOTOR_PORT_C
This port should be used together with port D.
brick.MOTOR_PORT_D
This port should be used together with port C.
Example
This example rotates two motors A and B alternately in opposite directions.
node node_modules/r-pi-brick/example/rotator.js
Running Tests
To run the test suite first install the development dependencies:
npm install
then run the tests:
npm test