Skip to content

WiringPi-Node library for reading analog photoresistors

License

Notifications You must be signed in to change notification settings

mikedamage/wpi-photocell

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

wpi-photocell

by Mike Green

A WiringPi-Node based library for reading analog photoresistors using a Raspberry Pi. It works by timing how long it takes to charge a capacitor that sits between the photocell and ground. You can find a tutorial on setting up the circuit on Adafruit. Conversion of microseconds to lux is planned, but not yet implemented.

Installation

npm install --save wpi-photocell

Usage

// As ES5 module:
var Photocell = require('wpi-photocell').Photocell;
var sensor = new Photocell(18); // use GPIO pin 18
// As ES6, if you're transpiling it yourself:
import { Photocell } from 'wpi-photocell/es6/lib/photocell';
const sensor = new Photocell(18);

Example

The measure() method is asynchronous, returning a promise that resolves to the number of microseconds:

sensor.measure().then((result) => {
  console.log(`It took ${result} microseconds to charge the capacitor`);
});
// => "It took 425.33 microseconds to charge the capacitor"

The Photocell class also fires events that you can subscribe to:

sensor.on('reading', (result) => console.log(result));
sensor.measure();
// => 425.33

There is also a synchronous measurement method that blocks until a result is returned:

let result = sensor.measureSync();
// => 425.33

Documentation

See the API docs

License

wpi-photocell is released under the terms of the MIT License.

About

WiringPi-Node library for reading analog photoresistors

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published