Skip to content

Instantly share code, notes, and snippets.

@mallendeo
Created June 26, 2016 06:03
Show Gist options
  • Save mallendeo/d2ed83b6dfa5c1c417536e5ce0479904 to your computer and use it in GitHub Desktop.
Save mallendeo/d2ed83b6dfa5c1c417536e5ce0479904 to your computer and use it in GitHub Desktop.
Get gpio sensors (Raspberry PI)
import gpio from 'gpio';
export default const sensor = (pins = [
{ num: 3, name: 'gate' },
{ num: 4, name: 'door' }
]) => {
let sensors = [];
const init = () => {
pins.map(pin => {
console.log('exporting', pin.num, pin.name);
sensors.push({
gpio: gpio.export(pin.num, {
direction: 'in',
interval: 50,
ready: () => {},
}),
name: pin.name,
});
});
}
const getSensors = () => sensors;
const getSensor = name => sensors.find(s => s.name === name);
return {
init,
getSensors,
getSensor,
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment