yapcduino.js
Yet another nodejs library for pcduino built for modern nodejs and provide more arduino functions and wrapper.
Yapcduino should work in Node.js 0.10 and 0.12 as well as io.js.
Install
npm install yapcduino --save
Usage
Basic Features
var p = ;p; // Set pin #10 to inputp; // Set pin #10 to input with pull-upvar ret = p;
p;p;p;
// Note: only 3, 5, 6, 9, 10, and 11 are PWM pinsp;var ret = p;
Global Mode
Sometimes it's silly to write all this functions with a prefix. Since yapcduino@0.9.0, we have introduced global mode.
global: true;;;
Arduino Binding
The following functions are provided using Node.js's Nan binding.
And can be called like pcduino.pinMode(0, pcduino.OUTPUT)
voidvoidintint/* * only pin (3/5/6/9/10/11) can be used as analog */voidvoid/* * pin(3/9/10/11) support frequency[125-2000]Hz @different dutycycle * pin(5/6) support frequency[195,260,390,520,781] @256 dutycycle */intunsigned longunsigned longvoidvoidvoidvoidunsigned longvoiduint8_t
Constants
HIGH: 0x1,
LOW: 0x0,
INPUT: 0x0,
OUTPUT: 0x1,
INPUT_PULLUP: 0x2,
LSBFIRST: 0,
MSBFIRST: 1,
CHANGE: 1,
FALLING: 2,
RISING: 3
Servo
global: true;var s = 3 type: 'SG90'; // available types: ['SG90']forvar i = 1; i <= 180; i += 5 Native; console; s;s;
jsdoc
/** * Construct a Servo object * * Note: pin(3/9/10/11) support frequency[125-2000]Hz @different dutycycle * pin(5/6) support frequency[195,260,390,520,781] @256 dutycycle * * @param * @param * @param * @param * @param * @param * @param */ {} /** * Set angle to given angle * * @param */Servoprototype {} /** * Return current angle */Servoprototype {} /** * Stop Servo */Servoprototype {}
SoftPWM (Powered by pthread)
Use your GPIO pin to fake PWM pin using CPU.
Improtant: SoftPWM may not be stable enough for your servo, which expects a pulse over a very tight range. Use SoftPWM in servo may cause positions jumps.
var pin = 0;var pwm = pin;var dutyCycle = 05;pwm; // run the PWM forever// everything done? stop and unset this.pin// Note: after detach, you have to attach(pin) before call write or readpwm;
var pin = 0;var pwm = pin;var dutyCycle = 05;var us = 20 * 1000; // 500HZpwm;// Get count of loops of the pin since last write (useful for stepping motor)var count = pwm;
jsdoc
{} /** * Attach the SoftPWM instance to a new pin * */SoftPWMprototype {} /** * Detach the SoftPWM instance from original pin (will unset output of original pin and set this.pin to null) * */SoftPWMprototype {} /** * Get count of loops of the pin since last write * */SoftPWMprototype {} /** * Writes a PWM wave to a p in (using digitalWrite). * To stop, simply call pwm.write(0) * * @see http://www.arduino.cc/en/Tutorial/PWM * @see http://www.arduino.cc/en/Reference/analogWrite * @param * @param * @param * @param * @param * @param */SoftPWMprototype {} /** * Read last set dutyCycle (will return undefined if not set) * */SoftPWMprototype {}
Source
The src/arduino comes from https://github.com/pcduino/c_environment
Authors
-
Zeno Zeng <zenoofzeng@gmail.com>
-
Senorsen <sen@senorsen.com>
Changelog
See: https://github.com/zenozeng/yapcduino.js/releases