01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | #include<Stepper.h> // 参考文件 /* 28BYJ-48.pdf 该参数根据电机每一转的步数来修改 */ const int stepsPerRevolution = 100; // 初始化步进电机要使用的Arduino的引脚编号 Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11); void setup() { // 设置转速,单位r/min myStepper.setSpeed(60); // 初始化串口 Serial.begin(9600); } void loop() { // 顺时针一次旋转 Serial.println( "clockwise" ); myStepper.step(stepsPerRevolution); delay(500); // 逆时针一次旋转 Serial.println( "counterclockwise" ); myStepper.step(-stepsPerRevolution); delay(500); } |
联系客服