Hiroshi M
/
StepperMotor
倒立振子ロボットで使用してるユニポーラのステッピングモータの駆動テストプログラムです。
Embed:
(wiki syntax)
Show/hide line numbers
main.cpp
00001 #include "mbed.h" 00002 #include "StepperMotor.h" 00003 00004 BusOut myleds(LED1, LED2, LED3, LED4); 00005 00006 Serial pc(USBTX, USBRX); 00007 00008 DigitalOut ae_fxma108(p29); 00009 00010 DigitalIn pb(p19); 00011 DigitalIn pw(p20); 00012 00013 const char Welcome_Message[] = 00014 "\r\nHello mbed World!\r\n" 00015 "Expand your creativity and enjoy making.\r\n\r\n" 00016 "Stepper Motor Test Mode.\r\n\r\n"; 00017 00018 00019 StepperMotor r_motor(p28,p27,p26,p25); 00020 StepperMotor l_motor(p24,p23,p22,p21); 00021 00022 int main() { 00023 pc.printf(Welcome_Message); 00024 00025 int old_pb=0; 00026 int new_pb; 00027 int old_pw=0; 00028 int new_pw; 00029 static int speed = 0; 00030 00031 pb.mode(PullUp); 00032 pw.mode(PullUp); 00033 00034 ae_fxma108 = 0; 00035 00036 r_motor.SetSpeed(speed,CLOCK_WISE); 00037 l_motor.SetSpeed(speed,ANTI_CLOCK_WISE); 00038 00039 r_motor.PulseEnable(); 00040 l_motor.PulseEnable(); 00041 00042 while(1) { 00043 new_pb = pb; 00044 if ((new_pb==0) && (old_pb==1)) { 00045 if (speed == 0) continue; 00046 speed--; 00047 pc.printf("speed: %d\r\n",speed); 00048 r_motor.SetSpeed(speed,CLOCK_WISE); 00049 l_motor.SetSpeed(speed,ANTI_CLOCK_WISE); 00050 } 00051 old_pb = new_pb; 00052 00053 00054 new_pw = pw; 00055 if ((new_pw==0) && (old_pw==1)) { 00056 if (speed == 10) continue; 00057 speed++; 00058 00059 pc.printf("speed: %d\r\n",speed); 00060 r_motor.SetSpeed(speed,CLOCK_WISE); 00061 l_motor.SetSpeed(speed,ANTI_CLOCK_WISE); 00062 } 00063 old_pw = new_pw; 00064 00065 myleds = speed; 00066 } 00067 }
Generated on Wed Jul 20 2022 12:05:17 by 1.7.2