Using same wiring from the blinky chapter, let’s now use external input to make the LED blink.
- Access
exercises/handle_inputin order to editmain.rs.
Exercise
We will use the button labelled BOOT linked to GPIO9 to toggle the LED.
- Initialise the peripherals with default config (check previous exercises)
- Set the
ledvariable toOutput::newpassingGPIO7peripheral,Level::Highand defaultOutputConfig. - Set the
btnvariable toInput::newpassingGPIO9peripheral, defaultInputConfigbut overwrite withas_pull(Pull::High). - Add the logic inside
loop- When pressing it should turn the
ledon, and delay it 2 seconds - Then it turns itself off.
- When pressing it should turn the
The exercises/handle_input/examples/handle_input.rs contains a solution. You can run it with the following command cargo run --example handle_input --release.