Skip to content

Commit 0b0ba28

Browse files
dalpilRahix
authored andcommitted
Adds a simple_pwm example for the trinket
1 parent e6822c1 commit 0b0ba28

File tree

1 file changed

+28
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)