Hardware & IoTLesson 101Free preview
RasPi LED & Pushbutton
This lesson is part of Node.js · All levels
Summary
This lesson combines the output and input of GPIO: LEDs that light up when a button is pressed on a Raspberry Pi. You'll configure one pin as input and one pin as output, and then react to a change in value via event watch. It's the foundation of the interactive hardware interface.
Key points
- One pin set 'in' for the button (with the pull-down resistor) and one pin set 'out' for the LED.
- Use pin.watch(callback) to react when the button is pressed or removed.
- Debounce is required because the contact button can bounce.
- Read the pin value with pin.readSync() when you need to check for up-to-date status.
- Make sure the voltage and resistor are as specified by Pi (3.3 V, not 5 V on the input pin).
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.