[ULN2003驅動板] 旋轉步進馬達通常稱為驅動,可以是波浪驅動、全步驅動、半步驅動驅動三種之一: 1.全步波浪驅動(Wave Drive)時序為:D->C->B->A ,轉一圈需要四步,一次僅驅動一個線圈工作,較少的消耗。 2.全步驅動(Full-Step Drive)時序為:AB->BC ->CD ->DA ,轉一圈需要四步,一次激勵兩個線圈,在最大扭矩下,更高的電流換來的是更高的扭矩。 3.半步驅動(Half-Step Drive)時序為:A->AB->B ->BC ->C ->CD ->D ->DA ,轉一圈需要八步,可使用半步驅動以獲得更精確的運動。 */ // change this to the number of steps on your motor #define STEPS 100 #define STEPS2 100 // create an instance of the stepper class, specifying // the number of steps of the motor and the pins it's // attached to Stepper stepper(STEPS, D5, D6, D7, D8); Stepper stepper2(STEPS2, D1, D2, D3, D4); // the previous reading from the analog input int previous = 0; int previous2 = 0; void setup() { // set the speed of the motor to 30 RPMs stepper.setSpeed(30); stepper2.setSpeed(30); }
void loop() { // get the sensor value int val = analogRead(0); int val2 = analogRead(0); // move a number of steps equal to the change in the // sensor reading stepper.step(val - previous); stepper2.step(val2 - previous2); // remember the previous value of the sensor previous = val; previous2 = val2; }