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 = Photocell;var sensor = 18; // use GPIO pin 18
// As ES6, if you're transpiling it yourself:;const sensor = 18;
Example
The measure()
method is asynchronous, returning a promise that resolves to the number of microseconds:
sensor;// => "It took 425.33 microseconds to charge the capacitor"
The Photocell
class also fires events that you can subscribe to:
sensor;sensor;// => 425.33
There is also a synchronous measurement method that blocks until a result is returned:
let result = sensor;// => 425.33
Documentation
See the API docs
License
wpi-photocell
is released under the terms of the MIT License.