blink

blinking led(s)
git clone igris.git:dracuxan/blink.git
Log | Files | Refs | README

commit b09a24cccb313b427486311068a2af3d22128422
parent e1929611000118e4670c4e6a26d6587444735707
Author: dracuxan <[email protected]>
Date:   Sun, 31 May 2026 00:46:19 +0530

new: flame-pump, laser-detect

Diffstat:
MCargo.toml | 3+--
MREADME.md | 55+++++++++++++++++++++++++++++++------------------------
Asrc/blink_led.rs | 11+++++++++++
Asrc/detect_laser.rs | 21+++++++++++++++++++++
Asrc/flame_pump.rs | 30++++++++++++++++++++++++++++++
Msrc/main.rs | 35+++++++++--------------------------
6 files changed, 103 insertions(+), 52 deletions(-)

diff --git a/Cargo.toml b/Cargo.toml @@ -1,9 +1,8 @@ [package] name = "blink" version = "0.1.0" -authors = ["dracuxan <[email protected]>"] edition = "2021" -license = "MIT OR Apache-2.0" +authors = ["dracuxan <[email protected]>"] [[bin]] name = "blink" diff --git a/README.md b/README.md @@ -1,34 +1,41 @@ -blink -===== +# blink -Rust project for the _Arduino Nano New Bootloader_. +Rust project for **Arduino Nano** experiments. Each module contains the logic for a different project — swap which one runs from `src/main.rs`. -## Build Instructions -1. Install prerequisites as described in the [`avr-hal` README] (`avr-gcc`, `avr-libc`, `avrdude`, [`ravedude`]). +## Modules -2. Run `cargo build` to build the firmware. +| Module | File | Description | +| ------------ | ------------------- | -------------------------------------------------------------------------------------- | +| `blink_led` | `src/blink_led.rs` | Built-in LED on D13 toggles every 500ms | +| `flame_pump` | `src/flame_pump.rs` | Reads flame sensor on A0, prints value to serial, runs pump via L298N when value < 125 | -3. Run `cargo run` to flash the firmware to a connected board. If `ravedude` - fails to detect your board, check its documentation at - <https://crates.io/crates/ravedude>. +## Usage -4. `ravedude` will open a console session after flashing where you can interact - with the UART console of your board. +In `src/main.rs`, uncomment the module you want to flash: -[`avr-hal` README]: https://github.com/Rahix/avr-hal#readme -[`ravedude`]: https://crates.io/crates/ravedude +```rust +#[arduino_hal::entry] +fn main() -> ! { + blink_led::run() + // flame_pump::run() +} +``` -## License -Licensed under either of +Then build and flash: - - Apache License, Version 2.0 - ([LICENSE-APACHE](LICENSE-APACHE) or <http://www.apache.org/licenses/LICENSE-2.0>) - - MIT license - ([LICENSE-MIT](LICENSE-MIT) or <http://opensource.org/licenses/MIT>) +```bash +cargo run +``` -at your option. +`ravedude` opens a serial console after flashing (57600 baud). -## Contribution -Unless you explicitly state otherwise, any contribution intentionally submitted -for inclusion in the work by you, as defined in the Apache-2.0 license, shall -be dual licensed as above, without any additional terms or conditions. +## Requirements + +- `avr-gcc`, `avr-libc`, `avrdude`, [`ravedude`](https://crates.io/crates/ravedude) +- See the [`avr-hal` README](https://github.com/Rahix/avr-hal#readme) + +## Adding a new module + +1. Create `src/my_module.rs` with a `pub fn run() -> !` entry point. +2. Add `mod my_module;` in `src/main.rs`. +3. Call `my_module::run()` from `main()`. diff --git a/src/blink_led.rs b/src/blink_led.rs @@ -0,0 +1,11 @@ +pub fn run() -> ! { + let dp = arduino_hal::Peripherals::take().unwrap(); + let pins = arduino_hal::pins!(dp); + + let mut led = pins.d13.into_output(); + + loop { + led.toggle(); + arduino_hal::delay_ms(500); + } +} diff --git a/src/detect_laser.rs b/src/detect_laser.rs @@ -0,0 +1,21 @@ +pub fn run() -> ! { + let dp = arduino_hal::Peripherals::take().unwrap(); + let pins = arduino_hal::pins!(dp); + + let mut adc = arduino_hal::Adc::new(dp.ADC, Default::default()); + let mut sensor = pins.a0.into_analog_input(&mut adc); + + let mut s = pins.d8.into_output(); + + loop { + let val: u16 = adc.read_blocking(&mut sensor); + + if val < 125 { + s.set_high(); + } else { + s.set_low(); + } + + arduino_hal::delay_ms(100); + } +} diff --git a/src/flame_pump.rs b/src/flame_pump.rs @@ -0,0 +1,30 @@ +pub fn run() -> ! { + let dp = arduino_hal::Peripherals::take().unwrap(); + let pins = arduino_hal::pins!(dp); + + let mut serial = arduino_hal::default_serial!(dp, pins, 57600); + + let mut adc = arduino_hal::Adc::new(dp.ADC, Default::default()); + let mut sensor = pins.a0.into_analog_input(&mut adc); + + let mut ena = pins.d9.into_output(); + let mut in1 = pins.d8.into_output(); + let mut in2 = pins.d7.into_output(); + + ena.set_high(); + + loop { + let val: u16 = adc.read_blocking(&mut sensor); + ufmt::uwriteln!(&mut serial, "{}", val).unwrap(); + + if val < 125 { + in1.set_high(); + in2.set_low(); + } else { + in1.set_low(); + in2.set_low(); + } + + arduino_hal::delay_ms(100); + } +} diff --git a/src/main.rs b/src/main.rs @@ -1,33 +1,16 @@ #![no_std] #![no_main] - use panic_halt as _; +#[allow(dead_code)] +mod blink_led; +#[allow(dead_code)] +mod detect_laser; +#[allow(dead_code)] +mod flame_pump; + #[arduino_hal::entry] fn main() -> ! { - let dp = arduino_hal::Peripherals::take().unwrap(); - let pins = arduino_hal::pins!(dp); - - let mut pin2 = pins.d2.into_output(); - let mut pin4 = pins.d4.into_output(); - let mut pin6 = pins.d6.into_output(); - let mut pin8 = pins.d8.into_output(); - - loop { - pin2.set_high(); - arduino_hal::delay_ms(1000); - pin2.set_low(); - - pin4.set_high(); - arduino_hal::delay_ms(1000); - pin4.set_low(); - - pin6.set_high(); - arduino_hal::delay_ms(1000); - pin6.set_low(); - - pin8.set_high(); - arduino_hal::delay_ms(1000); - pin8.set_low(); - } + // Call whichever module you want to flash: + detect_laser::run(); }