Created
August 7, 2017 04:37
-
-
Save zachwalton/721983be1faba20670f3bbd573201404 to your computer and use it in GitHub Desktop.
interacting with raspberry pi gpio via react-hardware
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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