Blinky
Let's see how to create the iconic Blinky.
Setup
✅ Go to intro/blinky
directory.
✅ Open the prepared project skeleton in intro/blinky
.
✅ Open the docs for this project with the following command:
cargo doc --open
intro/blinky/examples/blinky.rs
contains the solution. You can run it with the following command:
cargo run --release --example blinky
Exercise
On ESP32-C3-DevKit-RUST-1 there is a regular LED connected to GPIO 7. If you use another board consult the data-sheet.
Note that most of the development boards from Espressif today use an addressable LED which works differently and is beyond the scope of this book. In that case, you can also connect a regular LED to some of the free pins (and don't forget to add a resistor).
✅ Initiate the Io peripheral, and create a led
variable from GPIO connected to the LED, using the
into_push_pull_output
function.
Here we see that we can drive the pin high
, low
, or toggle
it.
We also see that the HAL offers a way to delay execution.
✅ Initialize a Delay instance.
✅ Using the [toggle()
][toggle] and delay_ms()
methods, make the LED blink every 500 ms.
Simulation
This project is available for simulation through two methods:
- Wokwi projects:
- Exercise: Currently not available
- Solution
- Wokwi files are also present in the project folder to simulate it with Wokwi VS Code extension:
- Press F1, select
Wokwi: Select Config File
and chooseintro/blinky/wokwi.toml
- Edit the
wokwi.toml
file to select between exercise and solution simulation
- Edit the
- Build you project
- Press F1 again and select
Wokwi: Start Simulator
- Press F1, select