当前位置:网站首页>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
边栏推荐
- 实例003:完全平方数 一个整数,它加上100后是一个完全平方数,再加上168又是一个完全平方数,请问该数是多少?
- Infected Tree(树形dp)
- [trio basic from introduction to mastery tutorial 20] trio calculates the arc center and radius through three points of spatial arc
- Meizu Bluetooth remote control temperature and humidity access homeassistant
- Synchronization of QT multithreading
- Relationship between line voltage and phase voltage, line current and phase current
- Anonymous structure in C language
- DokuWiki deployment notes
- Bluebridge cup internet of things basic graphic tutorial - GPIO input key control LD5 on and off
- QEMU STM32 vscode debugging environment configuration
猜你喜欢
Stm32--- systick timer
[trio basic tutorial 18 from introduction to proficiency] trio motion controller UDP fast exchange data communication
MySQL之MHA高可用集群
STM32 --- serial port communication
Charge pump boost principle - this article will give you a simple understanding
Sword finger offer 05 Replace spaces
Take you to understand the working principle of lithium battery protection board
OC and OD gate circuit
Matlab2018b problem solving when installing embedded coder support package for stmicroelectronic
实例008:九九乘法表
随机推荐
QEMU demo makefile analysis
STM32 virtualization environment of QEMU
Sql Server的存储过程详解
Step motor generates S-curve upper computer
Simple design description of MIC circuit of ECM mobile phone
实例003:完全平方数 一个整数,它加上100后是一个完全平方数,再加上168又是一个完全平方数,请问该数是多少?
Imx6ull bare metal development learning 1-assembly lit LED
Go dependency injection -- Google open source library wire
Shell script
Shell script realizes the reading of serial port and the parsing of message
My-basic application 2: my-basic installation and operation
Google sitemap files for rails Projects - Google sitemap files for rails projects
Void* C is a carrier for realizing polymorphism
Some thoughts on extracting perspectives from ealfa and Ebeta
STM32 outputs 1PPS with adjustable phase
Example 006: Fibonacci series
Arduino uses nrf24l01+ communication
STM32 --- GPIO configuration & GPIO related library functions
Slist of linked list
Imx6ull bare metal development learning 2- use C language to light LED indicator