final project update
Dependencies: mbed
Fork of DISCO_SMT32L4_pwm_PB3 by
main.cpp@4:9d26d117fa69, 2018-04-17 (annotated)
- Committer:
- carter7778
- Date:
- Tue Apr 17 21:04:18 2018 +0000
- Revision:
- 4:9d26d117fa69
- Parent:
- 3:9aa9bfe031bb
- Child:
- 5:620125c08317
led display
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bcostm | 0:4860a91fb495 | 1 | #include "mbed.h" |
bcostm | 0:4860a91fb495 | 2 | |
bcostm | 0:4860a91fb495 | 3 | PwmOut mypwm(PWM_OUT); |
carter7778 | 4:9d26d117fa69 | 4 | PwmOut ndpwm(LED1); |
carter7778 | 4:9d26d117fa69 | 5 | PwmOut rdpwm(JOYSTICK_LEFT); |
bcostm | 0:4860a91fb495 | 6 | |
bcostm | 0:4860a91fb495 | 7 | |
jblackann | 3:9aa9bfe031bb | 8 | #define UP 1 |
jblackann | 3:9aa9bfe031bb | 9 | #define DOWN 2 |
jblackann | 3:9aa9bfe031bb | 10 | |
bcostm | 0:4860a91fb495 | 11 | int main() { |
bcostm | 0:4860a91fb495 | 12 | |
jblackann | 3:9aa9bfe031bb | 13 | uint8_t i; |
jblackann | 3:9aa9bfe031bb | 14 | uint8_t count_dir; |
jblackann | 3:9aa9bfe031bb | 15 | |
jblackann | 3:9aa9bfe031bb | 16 | |
bcostm | 0:4860a91fb495 | 17 | mypwm.period_ms(10); |
bcostm | 0:4860a91fb495 | 18 | mypwm.pulsewidth_ms(1); |
bcostm | 0:4860a91fb495 | 19 | |
carter7778 | 4:9d26d117fa69 | 20 | ndpwm.period_ms(10); |
carter7778 | 4:9d26d117fa69 | 21 | ndpwm.pulsewidth_ms(1); |
carter7778 | 4:9d26d117fa69 | 22 | |
carter7778 | 4:9d26d117fa69 | 23 | rdpwm.period_ms(10); |
carter7778 | 4:9d26d117fa69 | 24 | rdpwm.pulsewidth_ms(1); |
carter7778 | 4:9d26d117fa69 | 25 | |
bcostm | 0:4860a91fb495 | 26 | printf("pwm set to %.2f %%\n", mypwm.read() * 100); |
carter7778 | 4:9d26d117fa69 | 27 | printf("2nd pwm set to %.2f %%\n", ndpwm.read() * 100); |
carter7778 | 4:9d26d117fa69 | 28 | printf("3rd pwm set to %.2f %%\n", rdpwm.read() * 100); |
bcostm | 0:4860a91fb495 | 29 | |
jblackann | 3:9aa9bfe031bb | 30 | count_dir = UP; |
bcostm | 0:4860a91fb495 | 31 | while(1) { |
carter7778 | 4:9d26d117fa69 | 32 | |
jblackann | 3:9aa9bfe031bb | 33 | for(i = 0; i < 10; i++ ) |
jblackann | 3:9aa9bfe031bb | 34 | { |
jblackann | 3:9aa9bfe031bb | 35 | wait(0.1); |
jblackann | 3:9aa9bfe031bb | 36 | if(count_dir == UP) |
jblackann | 3:9aa9bfe031bb | 37 | { |
carter7778 | 4:9d26d117fa69 | 38 | rdpwm = rdpwm + 0.5; |
carter7778 | 4:9d26d117fa69 | 39 | ndpwm = ndpwm + 0.25; |
jblackann | 3:9aa9bfe031bb | 40 | mypwm = mypwm + 0.01; |
jblackann | 3:9aa9bfe031bb | 41 | if(mypwm == 1.00) // if hit one, start counting down |
jblackann | 3:9aa9bfe031bb | 42 | { |
jblackann | 3:9aa9bfe031bb | 43 | count_dir = DOWN; |
jblackann | 3:9aa9bfe031bb | 44 | } |
jblackann | 3:9aa9bfe031bb | 45 | } |
jblackann | 3:9aa9bfe031bb | 46 | else if(count_dir == DOWN) |
jblackann | 3:9aa9bfe031bb | 47 | { |
carter7778 | 4:9d26d117fa69 | 48 | rdpwm = rdpwm - 0.5; |
carter7778 | 4:9d26d117fa69 | 49 | ndpwm = ndpwm - 0.25; |
jblackann | 3:9aa9bfe031bb | 50 | mypwm = mypwm - 0.01; |
jblackann | 3:9aa9bfe031bb | 51 | if(mypwm == 0.0) // if hit zero, start counting up |
jblackann | 3:9aa9bfe031bb | 52 | { |
jblackann | 3:9aa9bfe031bb | 53 | count_dir = UP; |
jblackann | 3:9aa9bfe031bb | 54 | } |
jblackann | 3:9aa9bfe031bb | 55 | } |
jblackann | 3:9aa9bfe031bb | 56 | |
jblackann | 3:9aa9bfe031bb | 57 | } |
jblackann | 3:9aa9bfe031bb | 58 | printf("pwm set to %.2f %%\n\r", mypwm.read() * 100); |
carter7778 | 4:9d26d117fa69 | 59 | printf("2nd pwm set to %.2f %%\n\r", ndpwm.read() * 100); |
carter7778 | 4:9d26d117fa69 | 60 | printf("3rd pwm set to %.2f %%\n\r", rdpwm.read() * 100); |
bcostm | 0:4860a91fb495 | 61 | } |
bcostm | 0:4860a91fb495 | 62 | } |