npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

yapcduino

v1.1.0

Published

Yet another nodejs library for pcduino (extends jheising's node.pcduino but provide simple API and some extra function).

Downloads

18

Readme

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 = require('yapcduino');
p.pinMode(10, p.INPUT); // Set pin #10 to input
p.pinMode(10, p.INPUT_PULLUP); // Set pin #10 to input with pull-up
var ret = p.digitalRead(10);
p.pinMode(0, p.OUTPUT);
p.digitalWrite(0, p.HIGH);
p.digitalWrite(0, p.LOW);
// Note: only 3, 5, 6, 9, 10, and 11 are PWM pins
p.analogWrite(3, 16);
var ret = p.analogRead(3);

Global Mode

Sometimes it's silly to write all this functions with a prefix. Since [email protected], we have introduced global mode.

require('yapcduino')({global: true});
pinMode(0, OUTPUT);
digitalWrite(0, HIGH);

Arduino Binding

The following functions are provided using Node.js's Nan binding. And can be called like pcduino.pinMode(0, pcduino.OUTPUT)

void pinMode(uint8_t, uint8_t);
void digitalWrite(uint8_t, uint8_t);
int digitalRead(uint8_t);
int analogRead(uint8_t);
/*
 * only pin (3/5/6/9/10/11) can be used as analog
 */
void analogReference(uint8_t mode);
void analogWrite(uint8_t, int);
/*
 * pin(3/9/10/11) support frequency[125-2000]Hz @different dutycycle
 * pin(5/6) support frequency[195,260,390,520,781] @256 dutycycle
 */
int pwmfreq_set(uint8_t pin, unsigned int freq);
unsigned long millis(void);
unsigned long micros(void);
void delay(unsigned long);
void delayMicroseconds(unsigned int us);
void delaySched(unsigned long);
void delayMicrosecondsSched(unsigned int us);
unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout);
void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val);
uint8_t shiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder);

Constants

HIGH: 0x1,
LOW: 0x0,

INPUT: 0x0,
OUTPUT: 0x1,
INPUT_PULLUP: 0x2,

LSBFIRST: 0,
MSBFIRST: 1,

CHANGE: 1,
FALLING: 2,
RISING: 3

Servo

require('yapcduino')({global: true});
var s = new Servo(3, {type: 'SG90'}); // available types: ['SG90']
for(var i = 1; i <= 180; i += 5) {
    Native.delay(100);
    console.log(i);
    s.write(i);
}
s.stop();

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 {Int} pin - pwm pin to use (only 3, 5, 6, 9, 10, and 11)
 * @param {Object} options - Options for servo
 * @param {String} options.type - Type of your servo, available types: ['default', 'SG90']
 * @param {Int} options.minPWM - PWM Value for angle 0, optional if options.type defined
 * @param {Int} options.maxPWM - PWM Value for angle max, optional if options.type defined
 * @param {Int} options.maxAngle - Max angle to reach, defaults 180, optional if options.type defined
 * @param {Int} options.frequency - Frequency, defaults to 390, optional if options.type defined
 */
function Servo(pin, options) {}

/**
 * Set angle to given angle
 *
 * @param {Int} angle - Angle in degree
 */
Servo.prototype.write = function(angle) {}

/**
 * Return current angle
 */
Servo.prototype.read = function() {}

/**
 * Stop Servo
 */
Servo.prototype.stop = function() {}

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 = new SoftPWM(pin);
var dutyCycle = 0.5;
pwm.write(dutyCycle, {frequency: 980, loops: Infinity}); // run the PWM forever
// everything done? stop and unset this.pin
// Note: after detach, you have to attach(pin) before call write or read
pwm.detach();
var pin = 0;
var pwm = new SoftPWM(pin);
var dutyCycle = 0.5;
var us = 20 * 1000; // 500HZ
pwm.write(dutyCycle, {period: us, loops: 1000});
// Get count of loops of the pin since last write (useful for stepping motor)
var count = pwm.getLoopCount();

jsdoc

function SoftPWM(pin) {}

/**
 * Attach the SoftPWM instance to a new pin
 *
 */
SoftPWM.prototype.attach = function(pin) {}

/**
 * Detach the SoftPWM instance from original pin (will unset output of original pin and set this.pin to null)
 *
 */
SoftPWM.prototype.detach = function() {}

/**
 * Get count of loops of the pin since last write
 *
 */
SoftPWM.prototype.getLoopCount = function() {}

/**
 * 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 {Float} dutyCycle - Duty Cycle [0, 1]
 * @param {Object} options - Options for PWM
 * @param {Int} options.period - Period (in us), defaults to 20 * 1000
 * @param {Int} options.frequency - Frequency, period will be ignored if frequency set
 * @param {Number} options.loops - (loops to live) How many loops should it run, defaults to Infinity (actually is 2147483647), note that -1 will be converted to 2147483647
 * @param {Bool} options.sync - Whether to run it in sync mode, defaults to false
 */
SoftPWM.prototype.write = function(dutyCycle, options) {}

/**
 * Read last set dutyCycle (will return undefined if not set)
 *
 */
SoftPWM.prototype.read = function() {}

Source

The src/arduino comes from https://github.com/pcduino/c_environment

Authors

Changelog

See: https://github.com/zenozeng/yapcduino.js/releases

Links