![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
scribe robot working with stepper motors
Dependencies: BLE_nRF8001 BNO055 HC_SR04_Ultrasonic_Library localization mbed-rtos mbed
Diff: stepper.cpp
- Revision:
- 6:ca112c3083bb
- Parent:
- 5:2c196f871096
--- a/stepper.cpp Wed May 04 23:51:57 2016 +0000 +++ b/stepper.cpp Thu May 12 06:12:45 2016 +0000 @@ -11,16 +11,17 @@ DigitalOut brown_r(p19); DigitalOut black_r(p20); -int wait_t = 60; +int wait_t = 20; int case_stepf = 0; +int case_stepb = 0; int case_right = 0; int case_left = 0; int case_rone = 0; //StepperMotorUni motor( p17, p18, p19, p20); -int step_f(){ - switch(case_stepf){ +int step_b(){ + switch(case_stepb){ case 0: //step 0101 black_l = 0; @@ -33,7 +34,7 @@ yellow_r = 1; wait_ms(wait_t); - case_stepf=1; + case_stepb=1; break; case 1: @@ -48,7 +49,7 @@ yellow_r = 0; wait_ms(wait_t); - case_stepf=2; + case_stepb=2; break; case 2: @@ -63,7 +64,7 @@ yellow_r = 0; wait_ms(wait_t); - case_stepf = 3; + case_stepb = 3; break; case 3: @@ -78,62 +79,75 @@ yellow_r = 1; wait_ms(wait_t); - case_stepf = 0; + case_stepb = 0; break; } return 1; } -int step_b(){ - //step 0101 - black_r = 0; - orange_r = 0; - brown_r = 1; - yellow_r = 1; - black_l = 1; - orange_l = 0; - brown_l = 0; - yellow_l = 1; - - wait_ms(wait_t); - - //step 1100 - black_r = 0; - orange_r = 1; - brown_r = 1; - yellow_r = 0; - black_l = 1; - orange_l = 1; - brown_l = 0; - yellow_l = 0; - - wait_ms(wait_t); - - //step 1010 - black_r = 1; - orange_r = 1; - brown_r = 0; - yellow_r = 0; - black_l = 0; - orange_l = 1; - brown_l = 1; - yellow_l = 0; - - wait_ms(wait_t); - - //step 0011 - black_r = 1; - orange_r = 0; - brown_r = 0; - yellow_r = 1; - black_l = 0; - orange_l = 0; - brown_l = 1; - yellow_l = 1; - - wait_ms(wait_t); - +int step_f(){ + switch(case_stepf){ + case 0: + //step 0101 + black_r = 0; + orange_r = 0; + brown_r = 1; + yellow_r = 1; + black_l = 1; + orange_l = 0; + brown_l = 0; + yellow_l = 1; + + wait_ms(wait_t); + case_stepf = 1; + break; + + case 1: + //step 1100 + black_r = 0; + orange_r = 1; + brown_r = 1; + yellow_r = 0; + black_l = 1; + orange_l = 1; + brown_l = 0; + yellow_l = 0; + + wait_ms(wait_t); + case_stepf = 2; + break; + + case 2: + //step 1010 + black_r = 1; + orange_r = 1; + brown_r = 0; + yellow_r = 0; + black_l = 0; + orange_l = 1; + brown_l = 1; + yellow_l = 0; + + wait_ms(wait_t); + case_stepf = 3; + break; + + case 3: + //step 0011 + black_r = 1; + orange_r = 0; + brown_r = 0; + yellow_r = 1; + black_l = 0; + orange_l = 0; + brown_l = 1; + yellow_l = 1; + + wait_ms(wait_t); + case_stepf = 0; + break; + } return 1; }