Library version for DC_Stepper_Controller_Lib with PWM speed control
Dependents: DR-ArmServoTest Auto_DC_pick_class MBed_TR1 ros_button_2021
Diff: sample_main.cpp
- Revision:
- 15:87df75ee8731
- Parent:
- 14:c9611cf036ad
diff -r c9611cf036ad -r 87df75ee8731 sample_main.cpp --- a/sample_main.cpp Thu May 27 07:32:49 2021 +0000 +++ b/sample_main.cpp Mon May 31 09:44:13 2021 +0000 @@ -10,45 +10,50 @@ DC_Motor_PID motor(D6,D3,D4,D5,792); //M1, M2, INA, INB, PPR -DigitalIn but(USER_BUTTON); +DigitalIn but(D9); // angle = 412 degree to move from one to another // angle = 100 degree to int main() { - motor.set_pid(0.008, 0, 0); + motor.set_pid(0.008, 0, 0, 0.10); Serial pc(USBTX, USBRX); // tx, rx pc.baud(9600); - while(1) + but.mode(PullDown); + + while(1){ + + wait(0.5);motor.set_out(0.4,0); + /*while(1) { - - while(!pc.readable()) - if(but) { motor.set_out(0,0); pc.printf("\n now: %d \n", motor.get_pulse()); break;} - if(pc.readable()) { - if(pc.getc() == '1') motor.set_out(0.6,0); - else if(pc.getc() == '2') motor.set_out(0,0.6); - } - else break; + if(but) {motor.set_out(0.4,0); pc.printf("\nbegin: %d \n", motor.get_pulse()); break;} + } + + wait(2); + */while(1) + { + if(but) { motor.set_out(0,0); pc.printf("\nend: %d \n", motor.get_pulse()); break;} } - /* - motor.set_out(1,0); - wait(5); - motor.set_out(0,1); - wait(5); - */ + wait(0.5); + motor.reset(); wait(0.5); - motor.move_angle(1000); // speed, 0 to 1 - wait(0.5); - motor.move_angle(-1000); // speed, 0 to 1 - wait(0.5); + motor.move_angle(615); + wait(2); + + motor.move_angle(412); // speed, 0 to 1 + wait(2); motor.move_angle(412); // speed, 0 to 1 - wait(0.5); + wait(2); + motor.move_angle(412); // speed, 0 to 1 + wait(2); motor.move_angle(412); // speed, 0 to 1 - wait(0.5); + wait(2); motor.move_angle(120); // speed, 0 to 1 + wait(2); + } } \ No newline at end of file