淳熙 姜
/
mbed_pwm
"SoftPWM.h"、"SoftPWM.cpp"を用いてサンプルを作った
Diff: main.cpp
- Revision:
- 0:6c227a6583fd
diff -r 000000000000 -r 6c227a6583fd main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Sun May 31 03:28:56 2015 +0000 @@ -0,0 +1,50 @@ +#include "mbed.h" +#include "SoftPWM.h" + +//SoftwarePWMのピン設定 +SoftPWM motor1A(dp1); +SoftPWM motor1B(dp2); +SoftPWM motor2A(dp13); +SoftPWM motor2B(dp14); +SoftPWM motor3A(dp17); +SoftPWM motor3B(dp18); +SoftPWM motor4A(dp25); +SoftPWM motor4B(dp26); + +int main() { + //パルス周期の設定 + motor1A.period_ms(1); + motor1B.period_ms(1); + motor2A.period_ms(1); + motor2B.period_ms(1); + motor3A.period_ms(1); + motor3B.period_ms(1); + motor4A.period_ms(1); + motor4B.period_ms(1); + + //初期化 + motor1A = 0.50; + motor1B = 0.50; + motor2A = 0.50; + motor2B = 0.50; + motor3A = 0.50; + motor3B = 0.50; + motor4A = 0.50; + motor4B = 0.50; + + while(1) { + //徐々に強くなるor弱くなる + for(int i=0;i<=0.50;i=i+0.01){ + motor1A = 0.50+i; + motor1B = 0.50-i; + motor2A = 0.50+i; + motor2B = 0.50-i; + motor3A = 0.50+i; + motor3B = 0.50-i; + motor4A = 0.50+i; + motor4B = 0.50+i; + wait(0.05); + } + wait(0.1); + } +}