Skip to content

Commit 7d1c888

Browse files
author
Bogdan Marinescu
committed
Added LED PWM test
1 parent bd51e4e commit 7d1c888

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

libraries/tests/mbed/pwm_led/pwm.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include "mbed.h"
2+
3+
#ifdef TARGET_NUCLEO_F103RB
4+
PwmOut led(D3);
5+
#else
6+
#error This test is not supported on this target.
7+
#endif
8+
9+
int main() {
10+
float crt = 1.0, delta = 0.05;
11+
12+
led.period_ms(2); // 500Hz
13+
while (true) {
14+
led.write(crt);
15+
wait_ms(50);
16+
crt = crt + delta;
17+
if (crt > 1.0) {
18+
crt = 1.0;
19+
delta = -delta;
20+
}
21+
else if (crt < 0) {
22+
crt = 0;
23+
delta = -delta;
24+
}
25+
}
26+
}

workspace_tools/tests.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,12 @@
408408
"dependencies": [MBED_LIBRARIES],
409409
"mcu": ["LPC1768", "LPC4088"]
410410
},
411-
411+
{
412+
"id": "MBED_31", "description": "PWM LED test",
413+
"source_dir": join(TEST_DIR, "mbed", "pwm_led"),
414+
"dependencies": [MBED_LIBRARIES],
415+
},
416+
412417
# CMSIS RTOS tests
413418
{
414419
"id": "CMSIS_RTOS_1", "description": "Basic",

0 commit comments

Comments
 (0)