极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7419|回复: 1

Stepper正反转程序

[复制链接]
发表于 2015-5-5 11:15:50 | 显示全部楼层 |阅读模式

#include&#160;<Stepper.h>
&#160;
const int stepsPerRevolution = 200;  // change this to fit the number of steps per revolution
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;// for your motor
&#160;
//&#160;initialize&#160;the&#160;stepper&#160;library&#160;on&#160;pins&#160;8&#160;through&#160;11:
Stepper myStepper1(stepsPerRevolution, 8,9,10,11);            
Stepper myStepper2(stepsPerRevolution, 11,9,10,8);    // counterclockwise         
&#160;
void setup() {
&#160;&#160;// set the speed at 60 rpm:
&#160;&#160;myStepper1.setSpeed(60);
&#160;&#160;myStepper2.setSpeed(60);
&#160;&#160;// initialize the serial port:
&#160;&#160;Serial.begin(9600);
}
&#160;
void loop() {
&#160;
&#160;&#160;// step one revolution  in one direction:
&#160;&#160;&#160;Serial.println("clockwise");
&#160;&#160;myStepper1.step(stepsPerRevolution);
&#160;&#160;delay(500);
&#160;
&#160;
&#160;&#160;&#160;// step one revolution in the other direction:
&#160;&#160;Serial.println("counterclockwise");
&#160;&#160;myStepper2.step(stepsPerRevolution);
&#160;&#160;delay(500);
&#160;
}

回复

使用道具 举报

发表于 2015-8-4 12:31:17 | 显示全部楼层
添加个开关或者传感就可以互动了
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则 需要先绑定手机号

Archiver|联系我们|极客工坊

GMT+8, 2024-3-29 13:26 , Processed in 0.045173 second(s), 19 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表