a stepper motor view as a serial midi device, use an interface such ttymidi to generate a serial to 115200 baudrate midi instrument
Dependencies: MIDI mbed X-NUCLEO-IHM05A1
Diff: main.cpp
- Revision:
- 16:1dc772fba09f
- Parent:
- 15:c781dda7e44c
- Child:
- 17:dc1b04f0b55d
diff -r c781dda7e44c -r 1dc772fba09f main.cpp --- a/main.cpp Fri Dec 07 11:21:04 2018 +0000 +++ b/main.cpp Fri Dec 07 17:40:15 2018 +0000 @@ -28,6 +28,8 @@ /* Motor Control Component. */ L6208 *motor; DigitalIn button (USER_BUTTON); +DigitalIn end(PC_10); +DigitalOut led(LED1); /* Functions -----------------------------------------------------------------*/ /** @@ -84,7 +86,7 @@ /* Attaching an error handler */ motor->attach_error_handler(&my_error_handler); - motor->set_step_mode(StepperMotor::STEP_MODE_1_4); + motor->set_step_mode(StepperMotor::STEP_MODE_1_8); /* Set speed, acceleration and deceleration to scale with microstep mode */ //motor->set_max_speed(2000); @@ -93,17 +95,42 @@ motor->set_max_speed(motor->get_max_speed()<<2); motor->set_acceleration(motor->get_acceleration()<<2); motor->set_deceleration(motor->get_deceleration()<<2); + printf(" init\n\r"); + end.mode(PullUp); + /* Request to go position 9000 (quarter steps) */ + motor->run(StepperMotor::BWD); + while(1) + { + // motor->wait_while_active(); + printf("while"); + if(end) break; + } + motor->hard_stop(); + led=1; - /* Request to go position 9000 (quarter steps) */ + int pos=motor->get_position(); + printf("pos:%d\n\r", pos); + motor->go_to(pos+200); + motor->wait_while_active(); + led=0; + wait(0.5); + + motor->set_home(); + wait(1); + + motor->go_to(1000<<4); + motor->wait_while_active(); + while (true) { - motor->go_to(3000); + motor->go_to(500<<4); motor->wait_while_active(); motor->go_to(0); motor->wait_while_active(); while (button) { + } }