当前位置:网站首页>Arduino+a4988 control stepper motor
Arduino+a4988 control stepper motor
2022-07-05 08:28:00 【Sharing master】

* foot 6(-en) Low level refers to starting motor (enable), It seems that you can not answer , Tried to run the same . But if you want to control the starting and closing of the motor, you still need to use
* foot 4(-dir) Control the direction with high and low levels .
* foot 5(-step) Drive the motor to rotate with high and low levels . Note the microsecond value of the waiting interval , If it is too fast, it will cause the motor to make a sound and do not rotate .
const int stepPin = 12; //D6
const int dirPin = 14; //D5
const int enable = 16; //D0
const int key1 = 5; //D1 Forward 0.5
const int key2 = 4; //D2 back off 0.5
const int key3 = 0; //D3 Back to 0
int ButtonState = HIGH;
void setup() {
// Sets the two pins as Outputs
pinMode(stepPin,OUTPUT);
pinMode(dirPin,OUTPUT);
pinMode(enable,OUTPUT);
pinMode(key1,INPUT_PULLUP);
pinMode(key2,INPUT_PULLUP);
pinMode(key3,INPUT_PULLUP);
Serial.begin(9600);
Serial.println("Sensor Test");
Serial.println("");
}
void step(boolean dir, int steps)
{
digitalWrite(enable, LOW);//enable
digitalWrite(dirPin, dir); //dir=1
delay(50);
for (int i = 0; i < steps; i++) {
digitalWrite(stepPin, HIGH);
delayMicroseconds(800);
digitalWrite(stepPin, LOW);
delayMicroseconds(800);
}
digitalWrite(enable, HIGH);//disable
}
void addone() // Forward 0.5
{
int reading = digitalRead(key1);
if (reading != ButtonState) {
delayMicroseconds(500);
reading = digitalRead(key1);
if (reading == LOW) {
step(true, 200); delay(500);
Serial.println("---------------- Forward --------------------");
}
}
}
void minone() // back off 0.5
{
int reading = digitalRead(key2);
if (reading != ButtonState) {
delayMicroseconds(500);
reading = digitalRead(key2);
if (reading == LOW) {
step(false, 200); delay(500);
Serial.println("---------------- back off --------------------");
}
}
}
void zreoone() // Back to 0
{
int reading = digitalRead(key3);
if (reading != ButtonState) {
delayMicroseconds(500);
reading = digitalRead(key3);
if (reading == LOW) {
for (int i = 0; i < 2; i++) {
step(false, 500); delay(500);
delayMicroseconds(800);
Serial.println("----------------KEY3--------------------");
}
}
}
}
void estkey() // Key judgment
{
Serial.println("----------------OK--------------------");
}
void loop()
{
addone();
minone();
zreoone();
}
Reference article Arduino+A4988+ Stepper motor Press the key to shake off
边栏推荐
- Array integration initialization (C language)
- Negative pressure generation of buck-boost circuit
- STM32 virtualization environment of QEMU
- H264 (I) i/p/b frame gop/idr/ and other parameters
- Brief discussion on Buck buck circuit
- Detailed summary of FIO test hard disk performance parameters and examples (with source code)
- QEMU demo makefile analysis
- Talk about the circuit use of TVs tube
- Soem EtherCAT source code analysis attachment 1 (establishment of communication operation environment)
- 第十八章 使用工作队列管理器(一)
猜你喜欢

Example 003: a complete square is an integer. It is a complete square after adding 100, and it is a complete square after adding 168. What is the number?

DokuWiki deployment notes

Stablq of linked list
![[tutorial 19 of trio basic from introduction to proficiency] detailed introduction of trio as a slave station connecting to the third-party bus (anybus PROFIBUS DP...)](/img/54/2fe86f54af01f10de93818103f2154.jpg)
[tutorial 19 of trio basic from introduction to proficiency] detailed introduction of trio as a slave station connecting to the third-party bus (anybus PROFIBUS DP...)

Take you to understand the working principle of lithium battery protection board

Example 008: 99 multiplication table

Talk about the function of magnetic beads in circuits

【三层架构及JDBC总结】

Semiconductor devices (III) FET

【三层架构】
随机推荐
Circleq of linked list
[three tier architecture]
Sql Server的存儲過程詳解
Sword finger offer 06 Print linked list from end to end
Soem EtherCAT source code analysis attachment 1 (establishment of communication operation environment)
General makefile (I) single C language compilation template
Semiconductor devices (I) PN junction
Go dependency injection -- Google open source library wire
My-basic application 1: introduction to my-basic parser
leetcode - 445. 两数相加 II
Bluebridge cup internet of things basic graphic tutorial - GPIO output control LD5 on and off
MHA High available Cluster for MySQL
Classic application of MOS transistor circuit design (1) -iic bidirectional level shift
STM32 --- NVIC interrupt
STM32 single chip microcomputer - external interrupt
第十八章 使用工作队列管理器(一)
Hardware and software solution of FPGA key chattering elimination
[tutorial 19 of trio basic from introduction to proficiency] detailed introduction of trio as a slave station connecting to the third-party bus (anybus PROFIBUS DP...)
[trio basic tutorial 18 from introduction to proficiency] trio motion controller UDP fast exchange data communication
Naming rules for FreeRTOS