找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 1913|回复: 4
收起左侧

arduino步进电机程序

[复制链接]
ID:28942 发表于 2018-7-7 11:07 | 显示全部楼层 |阅读模式
论坛很少有arduino的仿真,对不想买板子的坛友真没法验证代码正确与否,在这里贴个仿真供参考。
ATMEGA328最小系统
程序代码


#include <Stepper.h>

/*-----( Declare Constants, Pin Numbers)-----*/
//---( Number of steps per revolution ofINTERNAL motor in 4-step mode )---
#define STEPS_PER_MOTOR_REVOLUTION 32   

//---( Steps per OUTPUT SHAFT of gearreduction )---
#define STEPS_PER_OUTPUT_REVOLUTION 32 *64  //2048  


/*-----( Declare objects )-----*/
// create an instance of the stepper class,specifying
// the number of steps of the motor and thepins it's
// attached to
//-------------------------------------------------------------
//The pin connections need to be pins8,9,10,11 connected
// to Motor Driver In1, In2, In3, In4
//-------------------------------------------------------------

// Then the pins are entered here in thesequence 1-3-2-4 for proper sequencing
Steppersmall_stepper(STEPS_PER_MOTOR_REVOLUTION, 8, 10, 9, 11);

/*-----( Declare Variables )-----*/
int Steps2Take;

void setup()   /*----( SETUP: RUNS ONCE )----*/
{
// Nothing (Stepper Library sets pins as outputs)
}/*--(end setup )---*/

void loop()   /*----( LOOP: RUNS CONSTANTLY )----*/
{
Steps2Take  =  STEPS_PER_OUTPUT_REVOLUTION ;  // Rotate CW 1 turn
small_stepper.setSpeed(500);   
small_stepper.step(Steps2Take);
delay(1000);

Steps2Take  =  - STEPS_PER_OUTPUT_REVOLUTION;  // Rotate CCW 1 turn  
small_stepper.setSpeed(500);  //700 a good max speed??
small_stepper.step(Steps2Take);
delay(2000);
}





回复

使用道具 举报

ID:1 发表于 2018-7-8 03:16 | 显示全部楼层
缺少仿真
回复

使用道具 举报

ID:28942 发表于 2018-7-8 07:57 | 显示全部楼层

您好,我又重发了一遍,
回复

使用道具 举报

ID:1 发表于 2018-7-8 17:48 | 显示全部楼层
附件还是没加上呢 你看教程:http://www.51hei.com/bbs/dpj-49501-1.html
回复

使用道具 举报

ID:28942 发表于 2018-7-9 10:14 | 显示全部楼层
抱歉,上次没发成功,
回复

使用道具 举报

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

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

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