当前位置:网站首页>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
边栏推荐
- Design a clock frequency division circuit that can be switched arbitrarily
- Google sitemap files for rails Projects - Google sitemap files for rails projects
- Circleq of linked list
- Summary of SIM card circuit knowledge
- 实例007:copy 将一个列表的数据复制到另一个列表中。
- Count the number of inputs (C language)
- 【云原生 | 从零开始学Kubernetes】三、Kubernetes集群管理工具kubectl
- STM32 single chip microcomputer - external interrupt
- My-basic application 2: my-basic installation and operation
- Sizeof (function name) =?
猜你喜欢

99 multiplication table (C language)

Classic application of MOS transistor circuit design (2) - switch circuit design

UE像素流,来颗“减肥药”吧!

Talk about the circuit use of TVs tube

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?

实例007:copy 将一个列表的数据复制到另一个列表中。

剑指 Offer 05. 替换空格

Bluebridge cup internet of things basic graphic tutorial - GPIO output control LD5 on and off
![[three tier architecture]](/img/73/c4c75a453f03830e83cabb0762eb9b.png)
[three tier architecture]

STM32---IIC
随机推荐
Relationship between line voltage and phase voltage, line current and phase current
Working principle and type selection of common mode inductor
实例004:这天第几天 输入某年某月某日,判断这一天是这一年的第几天?
Google sitemap files for rails Projects - Google sitemap files for rails projects
Sql Server的存储过程详解
STM32---ADC
Example 004: for the day of the day, enter a day of a month of a year to judge the day of the year?
DokuWiki deployment notes
Cinq détails de conception du régulateur de tension linéaire
Sql Server的存儲過程詳解
实例010:给人看的时间
Sword finger offer 09 Implementing queues with two stacks
亿学学堂给的证券账户安不安全?哪里可以开户
每日一题——替换空格
Naming rules for FreeRTOS
The firmware of the connected j-link does not support the following memory access
【三层架构】
Weidongshan Internet of things learning lesson 1
2022.7.4-----leetcode.1200
关于线性稳压器的五个设计细节