Skip to content

Commit 36dc214

Browse files
dalpilRahix
authored andcommitted
Adds a simple_pwm example for arduino-uno
1 parent f0380a4 commit 36dc214

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*!
2+
* Example of using simple_pwm to fade a LED in and out on pin d5.
3+
*/
4+
#![no_std]
5+
#![no_main]
6+
7+
use arduino_hal::simple_pwm::*;
8+
use panic_halt as _;
9+
10+
#[arduino_hal::entry]
11+
fn main() -> ! {
12+
let dp = arduino_hal::Peripherals::take().unwrap();
13+
let pins = arduino_hal::pins!(dp);
14+
15+
let timer0 = Timer0Pwm::new(dp.TC0, Prescaler::Prescale64);
16+
17+
// Digital pin 5 is connected to a LED and a resistor in series
18+
let mut pwm_led = pins.d5.into_output().into_pwm(&timer0);
19+
pwm_led.enable();
20+
21+
loop {
22+
for x in (0..=255).chain((0..=254).rev()) {
23+
pwm_led.set_duty(x);
24+
arduino_hal::delay_ms(10);
25+
}
26+
}
27+
}

0 commit comments

Comments
 (0)