当前位置:网站首页>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
边栏推荐
- 【论文阅读】2022年最新迁移学习综述笔注(Transferability in Deep Learning: A Survey)
- 99 multiplication table (C language)
- [NAS1](2021CVPR)AttentiveNAS: Improving Neural Architecture Search via Attentive Sampling (未完)
- STM32 --- GPIO configuration & GPIO related library functions
- Soem EtherCAT source code analysis I (data type definition)
- Verilog -- state machine coding method
- General makefile (I) single C language compilation template
- leetcode - 445. Add two numbers II
- Array integration initialization (C language)
- Relationship between line voltage and phase voltage, line current and phase current
猜你喜欢
![[paper reading] the latest transfer ability in deep learning: a survey in 2022](/img/6b/b564fb7a6895329073fb5eaff64340.png)
[paper reading] the latest transfer ability in deep learning: a survey in 2022

每日一题——替换空格

Some thoughts on extracting perspectives from ealfa and Ebeta

UE pixel stream, come to a "diet pill"!

STM32 --- NVIC interrupt

MySQL之MHA高可用集群

Briefly talk about the identification protocol of mobile port -bc1.2
![[trio basic from introduction to mastery tutorial XIV] trio realizes unit axis multi-color code capture](/img/c5/22c6148873508b9205972e1ad970a3.jpg)
[trio basic from introduction to mastery tutorial XIV] trio realizes unit axis multi-color code capture

OC and OD gate circuit

Various types of questions judged by prime numbers within 100 (C language)
随机推荐
Google sitemap files for rails Projects - Google sitemap files for rails projects
实例002:“个税计算” 企业发放的奖金根据利润提成。利润(I)低于或等于10万元时,奖金可提10%;利润高于10万元,低于20万元时,低于10万元的部分按10%提成,高于10万元的部分,可提成7.
Imx6ull bare metal development learning 1-assembly lit LED
Stm32--- systick timer
Introduction of air gap, etc
2022.7.4-----leetcode.1200
[trio basic tutorial 18 from introduction to proficiency] trio motion controller UDP fast exchange data communication
The firmware of the connected j-link does not support the following memory access
Bluebridge cup internet of things competition basic graphic tutorial - clock selection
Example 006: Fibonacci series
Infected Tree(树形dp)
MATLAB小技巧(28)模糊综合评价
Sql Server的存儲過程詳解
Ble encryption details
Live555 push RTSP audio and video stream summary (III) flower screen problem caused by pushing H264 real-time stream
实例010:给人看的时间
Negative pressure generation of buck-boost circuit
【论文阅读】2022年最新迁移学习综述笔注(Transferability in Deep Learning: A Survey)
Void* C is a carrier for realizing polymorphism
Five design details of linear regulator