//! Template project for Rust on ESP32-C3 (`no_std`) based on [`esp-hal`](https://github.com/esp-rs/esp-hal)
//!
//! Useful resources:
//! - [The Rust on ESP Book](https://docs.esp-rs.org/book/)
//! - [Embedded Rust (no_std) on Espressif](https://docs.esp-rs.org/no_std-training/)
//! - [Matrix channel](https://matrix.to/#/#esp-rs:matrix.org)
#![no_std]
#![no_main]
use esp32c3_hal::{
clock::ClockControl,
delay::Delay,
peripherals::Peripherals,
prelude::*,
rmt::Rmt,
IO,
};
use esp_backtrace as _;
use esp_hal_smartled::{SmartLedsAdapter, smartleds::SmartLedsWrite};
use smart_leds::{brightness, RGB8};
#[riscv_rt::entry]
fn main() -> ! {
let peripherals = Peripherals::take().unwrap();
let system = peripherals.SYSTEM.split();
let clocks = ClockControl::boot_defaults(system.clock_control).freeze();
let io = IO::new(peripherals.GPIO, peripherals.IO_MUX);
let delay = Delay::new(&clocks);
let pin = io.pins.gpio2.into_push_pull_output();
let rmt = Rmt::new(peripherals.RMT, &clocks).unwrap();
let rmt_channel = rmt.channel0.configure(pin);
let mut led = SmartLedsAdapter::new(rmt_channel);
let colors = [
RGB8::new(255, 0, 0),
RGB8::new(0, 255, 0),
RGB8::new(0, 0, 255),
];
loop {
for color in colors {
let mut data = [color];
let iter = data.iter().copied();
led.write(brightness(iter, 64)).unwrap();
delay.delay_ms(500);
}
}
}