当前位置:网站首页>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
边栏推荐
- Detailed explanation of SQL server stored procedures
- [paper reading] the latest transfer ability in deep learning: a survey in 2022
- Live555 push RTSP audio and video stream summary (I) cross compilation
- Shell script realizes the reading of serial port and the parsing of message
- [trio basic from introduction to mastery tutorial 20] trio calculates the arc center and radius through three points of spatial arc
- 实例010:给人看的时间
- Live555 RTSP audio and video streaming summary (II) modify RTSP server streaming URL address
- Go dependency injection -- Google open source library wire
- [NAS1](2021CVPR)AttentiveNAS: Improving Neural Architecture Search via Attentive Sampling (未完)
- WiFi wpa_ Detailed description of supplicant hostpad interface
猜你喜欢
H264 (I) i/p/b frame gop/idr/ and other parameters
[tutorial 15 of trio basic from introduction to proficiency] trio free serial communication
MySQL之MHA高可用集群
Classic application of MOS transistor circuit design (1) -iic bidirectional level shift
实例007:copy 将一个列表的数据复制到另一个列表中。
[nas1] (2021cvpr) attentivenas: improving neural architecture search via attentive sampling (unfinished)
Example 008: 99 multiplication table
【云原生 | 从零开始学Kubernetes】三、Kubernetes集群管理工具kubectl
STM32 summary (HAL Library) - DHT11 temperature sensor (intelligent safety assisted driving system)
Hardware 3 -- function of voltage follower
随机推荐
实例001:数字组合 有四个数字:1、2、3、4,能组成多少个互不相同且无重复数字的三位数?各是多少?
Semiconductor devices (III) FET
matlab timeserise
[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...)
Example 008: 99 multiplication table
Briefly talk about the identification protocol of mobile port -bc1.2
go依赖注入--google开源库wire
Basic information commands and functions of kernel development
实例008:九九乘法表
【三层架构】
WiFi wpa_ Detailed description of supplicant hostpad interface
Wifi-802.11 negotiation rate table
STM32 single chip microcomputer -- volatile keyword
STM32 --- GPIO configuration & GPIO related library functions
leetcode - 445. Add two numbers II
DokuWiki deployment notes
STM32 single chip microcomputer - external interrupt
Installation and use of libjpeg and ligpng
Live555 push RTSP audio and video stream summary (III) flower screen problem caused by pushing H264 real-time stream
List of linked lists