![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
test
Dependencies: mbed
main.cpp
- Committer:
- xx123456987
- Date:
- 2016-09-09
- Revision:
- 0:41dfb0b1f108
File content as of revision 0:41dfb0b1f108:
#include "mbed.h" #define pwm_period_us 500 //#define pwm_pulsewidth_us 400 //實驗說明:利用鍵盤+-符號來控制馬達速度 PwmOut pwm_1(D9); PwmOut pwm_2(D10); PwmOut pwm_3(D11); float pwm = 0.5; DigitalIn button(USER_BUTTON); int main() { char a; pwm_1.period_us(pwm_period_us); pwm_2.period_us(pwm_period_us); pwm_3.period_us(pwm_period_us); pwm_1.write(0.5); pwm_2.write(0.5); pwm_3.write(0.5); printf("PWM all RESET to %.1f %%\n", pwm_1.read() * 100); while(1) { scanf("%c",&a); switch (a) { case '+': pwm += 0.05; pwm_1.write(pwm); pwm_2.write(pwm); pwm_3.write(pwm); printf("%c ; PWM all set to %.1f %%\n", a, pwm_1.read() * 100); break; case '-': pwm -= 0.05; pwm_1.write(pwm); pwm_2.write(pwm); pwm_3.write(pwm); printf("%c ; PWM all set to %.1f %%\n", a, pwm_1.read() * 100); break; /*case '3': pwm_3.write(pwm); printf("%c ; pwm_3 set to %.1f %%\n", a, pwm_3.read() * 100); break; case '0': pwm_1.write(0.5); pwm_2.write(0.5); pwm_3.write(0.5); printf("%c ; pwm all reset to %.1f %%\n", a, pwm_1.read() * 100); break; */ default: pwm_1.write(0.5); pwm_2.write(0.5); pwm_3.write(0.5); printf("PWM all RESET to %.1f %%\n", pwm_1.read() * 100); break; } } }