標(biāo)題: arduino步進(jìn)電機(jī)程序仿真 [打印本頁]
作者: wrlsohu 時(shí)間: 2018-7-8 07:56
標(biāo)題: arduino步進(jìn)電機(jī)程序仿真
仿真.png (28.76 KB, 下載次數(shù): 55)
下載附件
2018-7-8 07:56 上傳
論壇很少有arduino的仿真,對不想買板子的壇友真沒法驗(yàn)證代碼正確與否,在這里貼個(gè)仿真供參考。
ATMEGA328最小系統(tǒng)
程序代碼
#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);
}
歡迎光臨 (http://www.torrancerestoration.com/bbs/) |
Powered by Discuz! X3.1 |