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 🙏

© 2025 – Pkg Stats / Ryan Hefner

arduino-nes

v1.1.0

Published

A Library for connecting the serial/original nes controllers to an Arduino and node js.

Readme

Arduino Nes

A Library for connecting the serial/original nes controllers to an Arduino and node js.

Installation

Node Js.

npm install arduino-nes

Arduino.

Connect your arduino with an USB to your computer. Upload the code for the arduino to your arduino. See the arduino/arduino.ino

Schematics.

Note: The clock, latch and data wires must be connected to a digital pin on the arduino! Not a analog one!

alt text

Api.

Constructor:

  • serial - Required.
    In most cases: dev/tty.usbmodem1d1111

  • listen
    Start listening to the data stream from the arduino immediatly. (default: true)

  • controllers
    An array with 1 object for every controller. The object must contain the pin for the clock, latch and the data pin.

    Example: [{clock:2, latch:3, data:4}];

    Example with more controllers:

[
	{
		clock: 2,
		latch: 3,
		data: 4
	},
	{
		clock: 5,
		latch: 6,
		data: 7
	}
]

Note: at this point there is no maximum number of controllers. Keep in mind that the arduino has to loop through all your controllers!

Functions

  • startListening
    All controllers will listening and emitting events. The event startedListening will be emitted.

  • stopListening
    All controllers will stop listening and emitting events. The event stoppedListening will be emitted.

  • isListening
    Will return a boolean. true if the library is listening and false if it doesn't.

  • disconnect
    Disconnect the library from the arduino. The arduino is after this clear to use with other programs. The event disconnected will be emitted when the arduino is actually disconnected.

Events.

  • connected
    Emitted when the arduino is connected with the library.

  • disconnected
    Emitted when the arduino is disconnected from the library.

  • error(err)
    Emitted when there is an error.

  • ready Emitted when the controller are ready to use.

  • startedListening Emitted when the library has started listening for data events from the arduino. At this point the controllers can emit events.

  • stoppedListening Emitted when the library has stopped listening for data events from the arduino.

Controllers

  • getStates Get the states of all the buttons of this controller. An object will be returned in this format:
{
	right:		[boolean],
	left:		[boolean],
	down:		[boolean],
	up: 		[boolean],
	start:		[boolean],
	select:		[boolean]
	a:			[boolean],
	b:			[boolean]
}

The boolean will be true when the button is pressed at that moment. False means that the buttons is not pressed.

Events.

When a button of a controller is pressed or released the controller will emit an event.

  • down
  • downRelease
  • up
  • upRelease
  • left
  • leftRelease
  • right
  • rightRelease
  • select
  • selectRelease
  • start
  • startRelease
  • a
  • aRelease
  • b
  • bRelease

Wildcard event. Parameters: orginalEventname

  • * - This has the orginal event name as parameter.

Example


var Nes = require('arduino-nes');

var nes = new Nes({
	serial: "/dev/tty.usbmodem1d1131", // Make sure this is set to your port!
	controllers:[
		{
			clock: 2,
			latch: 3,
			data: 4
		}
	]
});

nes.on('error', function(){
	console.log('error', arguments);
}).on('ready', function(){
	console.log('ready', arguments);
}).on('connected', function(){
	console.log('connected', arguments);
}).on('disconnect', function(){
	console.log('disconnect', arguments);
});

// The first controller.
nes.controller[0].on('*', function(event){
	console.log('controller 0:', event);
})

// When the down button is released.
Nes.controllers[0].on('down', function(){
	// Do something.
});

// When the down button is released.
Nes.controllers[0].on('downReleased', function(){
	// Do something.
});

// Listen for all event from the second controller.
Nes.controllers[0].on('*', function(event){
	// Do something.
});