a easy way to control stepper
Dependents: Ex_stepper Example_for_learning_easy
Diff: stepper.cpp
- Revision:
- 2:8f2ae2b5c552
- Parent:
- 1:9a7c41e82ca5
--- a/stepper.cpp Fri Sep 07 14:09:04 2018 +0000 +++ b/stepper.cpp Tue Oct 16 07:31:28 2018 +0000 @@ -7,25 +7,25 @@ float now_x = 0, now_y = 0; -void rotate(Stepper stepper, double period, int pix) //id= 0--x,1--y pix=3200为一圈 +void rotate(stepper myStepper, double period, int pix) //id= 0--x,1--y pix=3200为一圈 { double half_period = period / 2.0; if (pix >= 0) { - stepper.dir = 1; + myStepper.dir = 1; } else { pix = -pix; - stepper.dir = 0; + myStepper.dir = 0; } for (int i = 0; i < pix; i++) { - stepper.step = 1; + myStepper.step = 1; wait(half_period); - stepper.step = 0; + myStepper.step = 0; wait(half_period); } } -void moveTo(Stepper xStepper, Stepper yStepper, double period, float x, float y) +void moveTo(stepper xStepper, stepper yStepper, double period, float x, float y) { rotate(xStepper, period, (x - now_x)*unit_xy); rotate(yStepper, period, (y - now_y)*unit_xy);