淳熙 姜
/
mbed_pwm
"SoftPWM.h"、"SoftPWM.cpp"を用いてサンプルを作った
Embed:
(wiki syntax)
Show/hide line numbers
main.cpp
00001 #include "mbed.h" 00002 #include "SoftPWM.h" 00003 00004 //SoftwarePWMのピン設定 00005 SoftPWM motor1A(dp1); 00006 SoftPWM motor1B(dp2); 00007 SoftPWM motor2A(dp13); 00008 SoftPWM motor2B(dp14); 00009 SoftPWM motor3A(dp17); 00010 SoftPWM motor3B(dp18); 00011 SoftPWM motor4A(dp25); 00012 SoftPWM motor4B(dp26); 00013 00014 int main() { 00015 //パルス周期の設定 00016 motor1A.period_ms(1); 00017 motor1B.period_ms(1); 00018 motor2A.period_ms(1); 00019 motor2B.period_ms(1); 00020 motor3A.period_ms(1); 00021 motor3B.period_ms(1); 00022 motor4A.period_ms(1); 00023 motor4B.period_ms(1); 00024 00025 //初期化 00026 motor1A = 0.50; 00027 motor1B = 0.50; 00028 motor2A = 0.50; 00029 motor2B = 0.50; 00030 motor3A = 0.50; 00031 motor3B = 0.50; 00032 motor4A = 0.50; 00033 motor4B = 0.50; 00034 00035 while(1) { 00036 //徐々に強くなるor弱くなる 00037 for(int i=0;i<=0.50;i=i+0.01){ 00038 motor1A = 0.50+i; 00039 motor1B = 0.50-i; 00040 motor2A = 0.50+i; 00041 motor2B = 0.50-i; 00042 motor3A = 0.50+i; 00043 motor3B = 0.50-i; 00044 motor4A = 0.50+i; 00045 motor4B = 0.50+i; 00046 wait(0.05); 00047 } 00048 wait(0.1); 00049 } 00050 }
Generated on Tue Jul 19 2022 15:23:49 by 1.7.2