Skip to content

Instantly share code, notes, and snippets.

@zachwalton
Created August 7, 2017 04:37
Show Gist options
  • Save zachwalton/721983be1faba20670f3bbd573201404 to your computer and use it in GitHub Desktop.
Save zachwalton/721983be1faba20670f3bbd573201404 to your computer and use it in GitHub Desktop.
interacting with raspberry pi gpio via react-hardware
/**
* Pulsing LED example.
* Insert an LED into Pin 9 and run this example.
*/
import Raspi from 'raspi-io';
import React, {Component} from 'react';
import ReactHardware from '../../src';
import five from 'johnny-five';
class BlinkingLed extends Component {
static defaultProps = {
port: 21,
period: 500,
};
componentDidMount() {
this.node = new five.Led(this.props.port);
this.node.blink(this.props.period);
}
componentWillReceiveProps(nextProps) {
if (this.props.period !== nextProps.period) {
this.node.blink(nextProps.period);
}
}
render() {
return null;
}
}
ReactHardware.render(
<BlinkingLed port={"GPIO21"} period={500} />,
new five.Board({
io: new Raspi(),
repl: false,
}),
(inst) => {
console.log('Rendered <%s />', BlinkingLed.name);
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment