"SoftPWM.h"、"SoftPWM.cpp"を用いてサンプルを作った

Dependencies:   SoftPWM mbed

Committer:
Kansuni
Date:
Sun May 31 03:28:56 2015 +0000
Revision:
0:6c227a6583fd
software PWM????????????????????????????

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Kansuni 0:6c227a6583fd 1 #include "mbed.h"
Kansuni 0:6c227a6583fd 2 #include "SoftPWM.h"
Kansuni 0:6c227a6583fd 3
Kansuni 0:6c227a6583fd 4 //SoftwarePWMのピン設定
Kansuni 0:6c227a6583fd 5 SoftPWM motor1A(dp1);
Kansuni 0:6c227a6583fd 6 SoftPWM motor1B(dp2);
Kansuni 0:6c227a6583fd 7 SoftPWM motor2A(dp13);
Kansuni 0:6c227a6583fd 8 SoftPWM motor2B(dp14);
Kansuni 0:6c227a6583fd 9 SoftPWM motor3A(dp17);
Kansuni 0:6c227a6583fd 10 SoftPWM motor3B(dp18);
Kansuni 0:6c227a6583fd 11 SoftPWM motor4A(dp25);
Kansuni 0:6c227a6583fd 12 SoftPWM motor4B(dp26);
Kansuni 0:6c227a6583fd 13
Kansuni 0:6c227a6583fd 14 int main() {
Kansuni 0:6c227a6583fd 15 //パルス周期の設定
Kansuni 0:6c227a6583fd 16 motor1A.period_ms(1);
Kansuni 0:6c227a6583fd 17 motor1B.period_ms(1);
Kansuni 0:6c227a6583fd 18 motor2A.period_ms(1);
Kansuni 0:6c227a6583fd 19 motor2B.period_ms(1);
Kansuni 0:6c227a6583fd 20 motor3A.period_ms(1);
Kansuni 0:6c227a6583fd 21 motor3B.period_ms(1);
Kansuni 0:6c227a6583fd 22 motor4A.period_ms(1);
Kansuni 0:6c227a6583fd 23 motor4B.period_ms(1);
Kansuni 0:6c227a6583fd 24
Kansuni 0:6c227a6583fd 25 //初期化
Kansuni 0:6c227a6583fd 26 motor1A = 0.50;
Kansuni 0:6c227a6583fd 27 motor1B = 0.50;
Kansuni 0:6c227a6583fd 28 motor2A = 0.50;
Kansuni 0:6c227a6583fd 29 motor2B = 0.50;
Kansuni 0:6c227a6583fd 30 motor3A = 0.50;
Kansuni 0:6c227a6583fd 31 motor3B = 0.50;
Kansuni 0:6c227a6583fd 32 motor4A = 0.50;
Kansuni 0:6c227a6583fd 33 motor4B = 0.50;
Kansuni 0:6c227a6583fd 34
Kansuni 0:6c227a6583fd 35 while(1) {
Kansuni 0:6c227a6583fd 36 //徐々に強くなるor弱くなる
Kansuni 0:6c227a6583fd 37 for(int i=0;i<=0.50;i=i+0.01){
Kansuni 0:6c227a6583fd 38 motor1A = 0.50+i;
Kansuni 0:6c227a6583fd 39 motor1B = 0.50-i;
Kansuni 0:6c227a6583fd 40 motor2A = 0.50+i;
Kansuni 0:6c227a6583fd 41 motor2B = 0.50-i;
Kansuni 0:6c227a6583fd 42 motor3A = 0.50+i;
Kansuni 0:6c227a6583fd 43 motor3B = 0.50-i;
Kansuni 0:6c227a6583fd 44 motor4A = 0.50+i;
Kansuni 0:6c227a6583fd 45 motor4B = 0.50+i;
Kansuni 0:6c227a6583fd 46 wait(0.05);
Kansuni 0:6c227a6583fd 47 }
Kansuni 0:6c227a6583fd 48 wait(0.1);
Kansuni 0:6c227a6583fd 49 }
Kansuni 0:6c227a6583fd 50 }