Tomasz Rodziewicz
/
Nucleo_LED_PWM_Pulsing
Program pulses the board LED from 0% to 100% and back using soft PWM. Tested on Nucleo F030R8.
main.cpp@0:ee3ee6288b15, 2014-05-27 (annotated)
- Committer:
- TRodziewicz
- Date:
- Tue May 27 16:54:20 2014 +0000
- Revision:
- 0:ee3ee6288b15
Program pulses the board LED from 0% to 100% and back using soft PWM.; ; Tested on Nucleo F030R8.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
TRodziewicz | 0:ee3ee6288b15 | 1 | #include "mbed.h" |
TRodziewicz | 0:ee3ee6288b15 | 2 | |
TRodziewicz | 0:ee3ee6288b15 | 3 | #define PWM_STEPS 100 |
TRodziewicz | 0:ee3ee6288b15 | 4 | #define PWM_SPEED 50 |
TRodziewicz | 0:ee3ee6288b15 | 5 | #define LED_ON 1 |
TRodziewicz | 0:ee3ee6288b15 | 6 | #define LED_OFF 0 |
TRodziewicz | 0:ee3ee6288b15 | 7 | |
TRodziewicz | 0:ee3ee6288b15 | 8 | DigitalOut myled(LED1); |
TRodziewicz | 0:ee3ee6288b15 | 9 | |
TRodziewicz | 0:ee3ee6288b15 | 10 | void blink_led(int from, int to) |
TRodziewicz | 0:ee3ee6288b15 | 11 | { |
TRodziewicz | 0:ee3ee6288b15 | 12 | for (int i = 0; i < PWM_STEPS; i++) { |
TRodziewicz | 0:ee3ee6288b15 | 13 | myled = from; |
TRodziewicz | 0:ee3ee6288b15 | 14 | wait_us(i * PWM_SPEED); |
TRodziewicz | 0:ee3ee6288b15 | 15 | |
TRodziewicz | 0:ee3ee6288b15 | 16 | myled = to; |
TRodziewicz | 0:ee3ee6288b15 | 17 | wait_us((PWM_STEPS - i) * PWM_SPEED); |
TRodziewicz | 0:ee3ee6288b15 | 18 | } |
TRodziewicz | 0:ee3ee6288b15 | 19 | } |
TRodziewicz | 0:ee3ee6288b15 | 20 | |
TRodziewicz | 0:ee3ee6288b15 | 21 | int main() { |
TRodziewicz | 0:ee3ee6288b15 | 22 | while (1) { |
TRodziewicz | 0:ee3ee6288b15 | 23 | blink_led(LED_ON, LED_OFF); |
TRodziewicz | 0:ee3ee6288b15 | 24 | blink_led(LED_OFF, LED_ON); |
TRodziewicz | 0:ee3ee6288b15 | 25 | } |
TRodziewicz | 0:ee3ee6288b15 | 26 | } |